0

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-> •)?

albanx
  • 6,193
  • 9
  • 67
  • 97

1 Answers1

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