Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ASCII TO UTF-8 Encoding

Tags:

php

ascii

utf-8

How to convert ASCII encoding to UTF8 in PHP

like image 734
user614856 Avatar asked Feb 13 '11 12:02

user614856


People also ask

Can you decode ASCII to UTF-8?

If we know that the current encoding is ASCII, the 'iconv' function can be used to convert ASCII to UTF-8. The original string can be passed as a parameter to the iconv function to encode it to UTF-8.

How do I change the encoding to UTF-8?

Click Tools, then select Web options. Go to the Encoding tab. In the dropdown for Save this document as: choose Unicode (UTF-8). Click Ok.

Is US Ascii same as UTF-8?

ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded. The bytes in the ASCII file and the bytes that would result from "encoding it to UTF-8" would be exactly the same bytes. There's no difference between them, so there's no need to do anything.


2 Answers

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

like image 75
Quentin Avatar answered Sep 21 '22 13:09

Quentin


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.

like image 20
Dmitri Avatar answered Sep 21 '22 13:09

Dmitri