Se connecter
Programmation › PHP › Encodage en PHP
2018-06-24 : Java StringEscapeUtils.escapeJava() made garbage in the database and the string is t\u00B0 %-\u00A3\u03C0.
Some solutions
/* 1 with json_decode */ $s = 't\u00B0 %-\u00A3\u03C0'; echo json_decode('"' . $s . '"'); /* 2 with mbstring */ $s = 't\u00B0 %-\u00A3\u03C0'; echo preg_replace_callback("/\\\\u([A-F0-9]{4})/", function ($a) { return mb_convert_encoding('&#x'.$a[1].';', 'UTF-8', 'HTML-ENTITIES'); }, $s); /* 3 with IntlChr */ $s = 't\u00B0 %-\u00A3\u03C0'; echo preg_replace_callback("/\\\\u([A-F0-9]{4})/", function ($a) { return IntlChar::chr(hexdec($a[1])); }, $s);
Of course, since escapeJava() will escape \n, \r, " and others characters, json_decode will decode the most of it.
Lire les commentaires | Laisser un commentaire