Re: Character encoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Build some script to convert to these comments.

Check this out:

<?php

// Fixes the encoding to uf8
function fixEncoding($in_str)
{
  $cur_encoding = mb_detect_encoding($in_str) ;

  if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
    return $in_str;
  else
    return utf8_encode($in_str);

} // fixEncoding
?>



Regards,
Igor Escobar
Systems Analyst & Interface Designer

+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar (twitter)





2009/8/5 b <php@xxxxxxx>

> On 08/05/2009 07:05 AM, Sándor Tamás (HostWare Kft.) wrote:
>
>> Hi,
>>
>> I have a mysql database, which the users can insert comments. As the users
>> can be from different countries, with different character encoding, the
>> mysql table can contain various special characters.
>>
>> How can I be sure to display these comments properly? I've found the
>> mb_convert_encoding, and for some characters it works okay, but there are
>> some really special characters which displayed as a '?'.
>>
>> Does anybody know some workarounds?
>>
>> Thanks,
>> SanTa
>>
>
> Use UTF-8. Create your database and its tables with UTF-8 char encoding.
> eg.
>
> ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
>
> Note there's no hyphen.
>
> Also, make sure the *data* is converted. You can use iconv for that.
>
> Next, ensure that the browser knows how to display the text. Use either a
> header or a meta tag (or both):
>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>
> This is especially important for the page with the comments form.
>
> Any SQL file with your data (for import) should have the following at the
> top:
>
> SET NAMES 'utf8';
>
> If you export a dump make sure that line is present before trying to
> import.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux