I have a problem about Unicode. I need a function in PHP to convert the string:
Xin chào tất cả các bạn. Mình không biết tiếng anh.
To:
Xin chao tat ca cac ban. Minh khong biet tieng anh.
Can anybody help me?
PHP | utf8_encode() FunctionThe utf8_encode() function is an inbuilt function in PHP which is used to encode an ISO-8859-1 string to UTF-8. Unicode has been developed to describe all possible characters of all languages and includes a lot of symbols with one unique number for each symbol/character.
For characters represented by the 7-bit ASCII character codes, the UTF-8 representation is exactly equivalent to ASCII, allowing transparent round trip migration. Other Unicode characters are represented in UTF-8 by sequences of up to 6 bytes, though most Western European characters require only 2 bytes3.
Why did UTF-8 replace the ASCII character-encoding standard? UTF-8 can store a character in more than one byte. UTF-8 replaced the ASCII character-encoding standard because it can store a character in more than a single byte. This allowed us to represent a lot more character types, like emoji.
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.
Use iconv
with the //TRANSLIT
modifier:
$str1 = "Xin chào tất cả các bạn. Mình không biết tiếng anh.";
$str2 = iconv("UTF-8", "ASCII//TRANSLIT", $str1);
print($str1.PHP_EOL.$str2);
The output will be:
Xin chào tất cả các bạn. Mình không biết tiếng anh.
Xin chao tat ca cac ban. Minh khong biet tieng anh.
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With