我有一个网址,我正在通过PHP调用(使用encodeURIComponent)传递,并在另一端用jQuery解码。我在PHP端发现了rawurldecode()之间的问题,但是当仅使用PHP来rawurlencode()和rawurldecode()测试URL时,我设法得到了同样的问题--有人能告诉我这里需要做什么吗?
复制:
$thing = rawurlencode("www.nzballet.org.nz?pa=thisthing&parmater1=23a¶mter2=another");
echo $thing;这将产生:
www.nzballet.org.nz%3Fpa%3Dthisthing%26parmater1%3D23a%26paramter2%3Danother
如果我这样做:
$rawurl = "www.nzballet.org.nz%3Fpa%3Dthisthing%26parmater1%3D23a%26paramter2%3Danother";
$decoded = rawurldecode($rawurl);
echo $decoded;我得到了:
www.nzballet.org.nz?pa=thisthing&parmater1=23a¶mter2=another
这是我在jQuery (ajax)和PHP之间传递时得到的相同输出,所以它与这一部分没有任何关系。我在HTML头文件中指定了charset=UTF-8 -有人能告诉我为什么我会在那里得到那个奇怪的字符吗?
谢谢!
发布于 2012-03-21 05:56:13
看起来您的web浏览器看到的是¶,并假设您指的是¶,它是段落符号(?)的实体。有关该问题的更多讨论,请参阅https://meta.stackexchange.com/questions/100905/para-turns-into-within-pre。
要解决此问题,请在显示实体之前使用htmlspecialchars对其进行编码:
$rawurl = "www.nzballet.org.nz%3Fpa%3Dthisthing%26parmater1%3D23a%26paramter2%3Danother";
$decoded = rawurldecode($rawurl);
echo htmlspecialchars($decoded);从手册中:
某些字符在超文本标记语言中具有特殊的意义,如果要保留其含义,则应使用超文本标记语言实体来表示。
..。
'&‘(与符号)变成'&'
https://stackoverflow.com/questions/9795521
复制相似问题