Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode in PHP?

I heard PHP has very poor Unicode support. So what does it take to make a PHP 5 built application Unicode supported under PHP 5.3+? Would mbstring be the only option here? How has Facebook or Yahoo gotten around this PHP limitation?

like image 625
Ernest Avatar asked Dec 20 '11 09:12

Ernest


People also ask

Does PHP support Unicode?

PHP does not offer native Unicode support. PHP only supports a 256-character set. However, PHP provides the UTF-8 functions utf8_encode() and utf8_decode() to provide some basic Unicode functionality.

What is character u '\ xe9?

The unicode string for \xe9 is an accented e - é

What is a Unicode example?

Unicode supports more than a million code points, which are written with a "U" followed by a plus sign and the number in hex; for example, the word "Hello" is written U+0048 U+0065 U+006C U+006C U+006F (see hex chart).

What is UTF-8 PHP?

Definition and Usage. The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.


2 Answers

PHP has no low-level support for any encoding. But all that actually means is that it doesn't care on a language level. Strings in PHP are raw byte sequences, which can be in any encoding you like. When handling multi-byte strings, you need to take care to use the right string manipulation function instead of possibly screwing with the byte stream directly. So the only "non-support" of Unicode is that it doesn't include the concept of encodings into the core language itself, but you can still work with any encoding perfectly fine by manipulating strings using the appropriate string function.

Actually, if you just take a little care to keep everything in UTF-8 all the time, you will rarely have to worry about anything regarding encodings. PHP works just fine with Unicode.

For extensive coverage of this topic, please see What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text.

like image 153
deceze Avatar answered Oct 13 '22 01:10

deceze


PHP has poor Unicode support, but it's not impossible to do it, you just have to be careful with the functions you are using and their support for unicode. This page has a good summary of unicode support for the different functions and extensions http://www.phpwact.org/php/i18n/utf-8

like image 32
applechief Avatar answered Oct 13 '22 01:10

applechief