3
When I insert 1ª
in JSON with codeigniter, when turning into string it turns 1\u00aa
.
$t[0]["teste"] = "1ª";
$data[0]["algo"] = $t;
3
When I insert 1ª
in JSON with codeigniter, when turning into string it turns 1\u00aa
.
$t[0]["teste"] = "1ª";
$data[0]["algo"] = $t;
2
Normal. PHP uses the format \u quatro-dígitos-hex
to escape special characters (non-ASCII). This is valid JSON, see json.org
If you really want to avoid escape, you can use the option JSON_UNESCAPED_UNICODE
:
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"
Browser other questions tagged php json
You are not signed in. Login or sign up in order to post.
And there’s some way to save how
ª
within JSON, or it only allows for character code ??– Lucas Caresia
You’re already saving the
ª
, it is only being represented in hexadecimal. When you consume JSON, values are typically decoded. For example: type'\u00aa'
and enter the Devtools console of your browser. It will be displayedª
.– rodorgas
You can send a th directly to JSON yes, but it is not recommended because you may have some decoding problem. Your web framework is doing the automatic conversion for you. If you generate JSON manually, you can put the latter in this form.
– rodorgas
In case, I take a string from the database, use
json_decode
, enter the information, and then usejson_encode
, and put it back in the database, and there in the database appears\u00aa
, the problem may be in the database ??– Lucas Caresia
Use json_decode before sending to database.
– rodorgas
As it is in array, I use the
json_encode
to turn into string to be able to insert into the database. In case I usejson_decode
in an array it saysjson_decode() expects parameter 1 to be string, array given
, I didn’t quite understand what you wanted me to do.– Lucas Caresia
Let’s go continue this discussion in chat.
– rodorgas