PHP - converting ASCII to Unicode in a mixed string

I have a string with Unicode and ASCII characters.

I can use utf8_decodeto convert ASCII to Unicode characters, but also converts unicode to Unicode characters. How can I filter or convert only ASCII characters to Unicode in a mixed string?

For instance:

utf8_decode(& #225; rỉ);
~> á rỉ
+3
source share
3 answers

Two things. ASCII characters are 7-bit, from 0x00 to 0x7F. Therefore, if you have a Unicode string, ASCII characters do not need to be converted, because they are the same in Unicode ...

á 0xE1, ASCII, ISO Latin 1. ( ...). , ISO Latin 1 UTF-8.

+3

á ASCII. ASCII

.

echo mb_convert_encoding('á rỉ', "UTF-8", "UTF-8");
+1

you can use $string = iconv('ASCII//TRANSLIT','UTF-8', $string);

-1
source

All Articles