tags:

views:

225

answers:

2

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?

+2  A: 

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
Luis Melgratti
Can I use this on the raw string format of JSON? Will this cause mailformation in the JSON structure?
Pentium10
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
$a and $b won't work for Esperanto accented characters ;-P
Timothy
A: 

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

Purefan