Unicode character converting encode
Hello Often i have to import xml files with php, but this files contains some strange characters ex.:\u2022 (corresponding to开发者_如何学编程 • real char ) , \u2019 and so on. Is there any function in php to convert this chars to their respective real char (ex. \u2022-> •)?
I'm assuming that you want to fix errors in poorly built third-party XML you have no control on. It's hard to say without a real sample but \u2019 is the JavaScript syntax to encode Unicode characters. Given that, you can handle your input as a JavaScript string rather than plain text. The json_decode() function can help you:
<?php
$input = '\u2022 (corresponding to • real char ) , \u2019';
$output = json_decode('"' . $input . '"');
Now $output
contains • (corresponding to • real char ) , ’
.
精彩评论