user2727492
user2727492

Reputation: 13

Conversion of mixed ASCII string with multi-byte sequences to proper UTF-8

Please consider the following ASCII string that comes in from a CSV file:

Foo\xe2\x80\x99s Bar

Using PHP, how can one reliably convert this to UTF-8 so that the value is:

Foo’s Bar

Upvotes: 1

Views: 147

Answers (1)

Larry.Z
Larry.Z

Reputation: 3724

If you get the string value printed as Foo\xe2\x80\x99s Bar, then in php the string can be defined like this

$str = "Foo\\xE2\\x80\\x99s Bar";

You can get the string printed as Foo’s Bar using the eval() method.

eval("\$value = \"Foo\\xE2\\x80\\x99s Bar\";");
echo $value;

The result display Foo’s Bar.

Upvotes: 1

Related Questions