开发者

Remove accents from a JSON response

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 wou开发者_如何转开发ld like to keep the JSON format intact, as I will send it towards.

How can I do this?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜