尝试爆炸字符串时出现问题
我正在尝试使用爆炸将文本拆分为数组,但由于某种原因,当文本来自发布的表单时,这不起作用。
如果我运行 explode('|§|', 'qwe|§|asd|§|zxc');
我将得到一个如下数组:
Array
(
[0] => qwe
[1] => asd
[2] => zxc
)
BUT
如果此输入文本来自这样的表单定义:
<form method="post">
Input: <input type="text" name="query" size="50" value="qwe|§|asd|§|zxc"><input type="submit" value="Parse">
</form>
我得到以下数组:
Array
(
[0] => qwe|§|asd|§|zxc
)
我猜这与 iso 设置有关,并且“查询”字段中的文本已以某种方式更改,但我不明白如何修复。我尝试设置 和其他字符集,但无济于事。
有什么想法吗?提前致谢。
I am trying to split a text into an array using explode, but for some reason that does not work when the text is coming from a posted form.
If I run explode('|§|', 'qwe|§|asd|§|zxc');
I will get an array like:
Array
(
[0] => qwe
[1] => asd
[2] => zxc
)
BUT
If this input text comes from a form define like:
<form method="post">
Input: <input type="text" name="query" size="50" value="qwe|§|asd|§|zxc"><input type="submit" value="Parse">
</form>
I am getting the following array:
Array
(
[0] => qwe|§|asd|§|zxc
)
Im guessing this has to do with iso settings and that the text in the 'query' field has been altered in some way, but I can't understand how to fix. I have tried setting <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
and other charsets, but to no avail.
Any ideas? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是一个想法:§ 符号可能会转换为 url 格式。首先尝试 urldecode() 字符串。
Just an idea: The § sign is probably be converted to url format. Try urldecode() the string first.
我可能弄错了,但
§
可能是一个 unicode 字符,PHP 尚不支持。因此,从表单转移到脚本时可能会出现一些问题。您是否尝试过将其更改为更...正常的内容?就像如果您改为使用
qwe|~|asd|~|zxc
,或者如果您担心的话,可能是qwe|+~+|asd|+~+|zxc
有人会输入什么I'm probably mistaken on this, but
§
may be a unicode character, which PHP does not yet support. Thus, there may be some issues when transferring from the form to the script.Have you tried changing it to something more... normal? Like if you did
qwe|~|asd|~|zxc
instead, or maybeqwe|+~+|asd|+~+|zxc
if you're concerned about what somebody would enter