Removing accents from a JSON response

I get a JSON response on a social networking site. There are some accented characters that I would like to remove.

Example: L \ u00e1szl \ u00f3 M \ u00e1rton who reads "László Márton" and I would like to be converted to Laszlo Marton.

I would like to leave the JSON format intact since I will send it.

How can i do this?

+3
source share
2 answers

See accepted by anwser: How to 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 the server is configured correctly (as indicated in the reference question), this should work.

Edit: this is not the case.

It 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
+2
source

Source: https://habr.com/ru/post/1743282/


All Articles