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-> •)?
            Asked
            
        
        
            Active
            
        
            Viewed 2,268 times
        
    0
            
            
        - 
                    possible duplicate of [Convert "php unicode" to character](http://stackoverflow.com/questions/4261881/convert-php-unicode-to-character) – Pekka Dec 23 '10 at 16:39
 - 
                    It seems that a found a solution using base64.encode/decode. – albanx Dec 25 '10 at 10:49
 - 
                    Please refer this link http://www.ibm.com/developerworks/library/os-php-unicode/index.html – Pradeep Singh Dec 23 '10 at 16:39
 
1 Answers
3
            
            
        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 ) , ’.
        Álvaro González
        
- 142,137
 - 41
 - 261
 - 360