3

I get back a JSON response from a social networks site. There are certain accented characters that I would like to be removed.

An example is : L\u00e1szl\u00f3 M\u00e1rton, that reads "László Márton" and I would like to be transformed into Laszlo Marton.

I would like to keep the JSON format intact, as I will send it towards.

How can I do this?

Pentium10
  • 204,586
  • 122
  • 423
  • 502

2 Answers2

2

See accepted anwser to: How do I remove accents from characters in a PHP string?

$input = "Fóø Bår";

setlocale(LC_ALL, "en_US.utf8");
$output = iconv("utf-8", "ascii//TRANSLIT", $input);

print($output);

if server is correctly configured (as the reference question states) this should work.

Edit: it doesn't.

This will do :)

$string = current(json_decode('["L\u00e1szl\u00f3 M\u00e1rton"]'));

$a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ';
$b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
$string = utf8_decode($string);
$string = strtr($string, utf8_decode($a), $b);

echo $string; // output > Laszlo Marton
Community
  • 1
  • 1
Luis Melgratti
  • 11,881
  • 3
  • 30
  • 32
  • Can I use this on the raw string format of JSON? Will this cause mailformation in the JSON structure? – Pentium10 Apr 29 '10 at 05:31
  • Use it after decoding JSON. In theory, you could also replace within the JSON representation itself (using unicode codes like \u00e1 as the source). – Joel L Apr 29 '10 at 14:53
0

you can try the functions here http://hsivonen.iki.fi/php-utf8/

Purefan
  • 1,498
  • 24
  • 44