Convert ASCII TO UTF-8 Encoding

2022-08-30 13:17:47

How to convert ASCII encoding to UTF8 in PHP


答案 1

ASCII is a subset of UTF-8, so if a document is ASCII then it is already UTF-8.


答案 2

If you know for sure that your current encoding is pure ASCII, then you don't have to do anything because ASCII is already a valid UTF-8.

But if you still want to convert, just to be sure that its UTF-8, then you can use iconv

$string = iconv('ASCII', 'UTF-8//IGNORE', $string);

The IGNORE will discard any invalid characters just in case some were not valid ASCII.


推荐