了解\ u0000在PHP/JSON中的含义并摆脱它 [英] Understanding what \u0000 is in PHP / JSON and getting rid of it

查看:875
本文介绍了了解\ u0000在PHP/JSON中的含义并摆脱它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道发生了什么,但是我在数组中有一个字符串.它必须是一个字符串,因为我首先在上面运行了它:

I haven't a clue what is going on but I have a string inside an array. It must be a string as I have ran this on it first:

$array[0] = (string)$array[0];

如果我以纯文本格式将$ array [0]输出到浏览器,则会显示以下内容:

If I output $array[0] to the browser in plain text it shows this:

hellothere

但是,如果我对$ array进行JSON编码,我会得到:

But if I JSON encode $array I get this:

hello\u0000there

此外,我需要将有"部分(在\ u0000之后的部分)分开,但这不起作用:

Also, I need to separate the 'there' part (the bit after the \u0000), but this doesn't work:

explode('\u0000', $array[0]);

我什至不知道\ u0000是什么,也不知道如何在PHP中对其进行控制.

I don't even know what \u0000 is or how to control it in PHP.

我确实看到了此链接:尝试从我的json中查找并摆脱此\ u0000 ...这建议str_replacing生成的JSON.我无法做到这一点(并且需要首先如上所述将其分开),因此我随后在Google中检查了"PHP检查反斜杠\ 0字节",但是我仍然不知道该怎么做.

I did see this link: Trying to find and get rid of this \u0000 from my json ...which suggests str_replacing the JSON that is generated. I can't do that (and need to separate it as mentioned above first) so I then checked Google for 'php check for backslash \0 byte' but I still can't work out what to do.

推荐答案

\uXXXX是JSON Unicode转义符号(X是十六进制).

\uXXXX is the JSON Unicode escape notation (X is hexadecimal).

在这种情况下,它意味着0 ASCII字符(也称为NUL字节),可以将其拆分:

In this case, it means the 0 ASCII char, aka the NUL byte, to split it you can either do:

explode('\u0000', json_encode($array[0]));

或更妙的是:

explode("\0", $array[0]); // PHP doesn't use the same notation as JSON

这篇关于了解\ u0000在PHP/JSON中的含义并摆脱它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆