php – 1ª if it returns 1 \ u00aa when I insert no json

Question:

When I insert in JSON with codeigniter, when I transform it to string it becomes 1\u00aa .

$t[0]["teste"] = "1ª";
$data[0]["algo"] = $t;

Answer:

Normal. PHP uses the \u quatro-dígitos-hex format to escape special (non-ASCII) characters. This is valid JSON, see json.org

If you really want to avoid the escape, you can use the JSON_UNESCAPED_UNICODE option:

php > // com a flag:
php > print(json_encode('ºªáéíóú',JSON_UNESCAPED_UNICODE));
"ºªáéíóú"

php > // sem a flag:
php > print(json_encode('ºªáéíóú'));
"\u00ba\u00aa\u00e1\u00e9\u00ed\u00f3\u00fa"
Scroll to Top