Unicode in PHP?

I heard that PHP has very low Unicode support. So what does it take to make a PHP 5 Unicode-enabled application supported in PHP 5.3+? Would mbstring be the only option here? How did Facebook or Yahoo get this PHP restriction?

+7
source share
4 answers

PHP does not support low-level support for any encoding. But all this really means that he does not care about the language level. Strings in PHP are raw byte sequences that can be in any encoding you like. When processing multi-byte strings, you need to take care to use the correct string manipulation function, rather than directly screwing the byte stream. Thus, the only β€œnon-support” of Unicode is that it does not include the concept of encoding in the main language, but you can still work perfectly with any encoding by manipulating strings using the corresponding string function.

In fact, if you just took care of everything in UTF-8 all the time, you rarely have to worry about anything about encodings. PHP works great with Unicode.

For a detailed coverage of this topic, please see. What every programmer absolutely, should know positively about encodings and character sets for working with text .

+8
source

PHP has poor Unicode support, but this is not impossible to do, you just need to be careful with the functions you use and their support for unicode. This page has a good summary of unicode support for various functions and extensions http://www.phpwact.org/php/i18n/utf-8

+1
source

If the data comes from tables using UTF-8, you should just set the correct headers and meta, and you should be fine (no encoding needed):

<?php header ('Content-type: text/html; charset=utf-8'); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> </body> </html> 
0
source

The following mbstring variables must be set via php.ini or vhost-configuration (httpd.conf; does not work in the directory [via .htaccess]):

 mbstring.language = Neutral mbstring.internal_encoding = UTF-8 mbstring.func_overload = 7 

Just leave the code as it is, make sure your editor / IDE saves files only as UTF-8 and delivers everything as UTF-8 (via an HTTP header or META tag).

See also: PHP Manual - multibyte string - function overload function

-one
source

All Articles