2014-09-25 544 views
0

我有一个使用输入字段进行搜索的页面,然后使用相同的字段遍历页面。它也接受双引号进行精确搜索。在URL中处理%22

该网址需要看起来像blahblah.com/search/%22querystuff%22,但它自动默认为blahblah.com/search/"querystuff“在浏览器中失败。

有什么办法让它停止这样做,或者我需要看看不同的方法。

+0

我不能完全确定是什么问题(如果你提供的有问题的代码,这将有助于),但它听起来像你的问题归结为一个[这个副本](http://stackoverflow.com/questions/1996122/how-to-prevent-xss-with-html-php)。 – Quentin 2014-09-25 20:09:26

+1

我想你想[urlencode()](http://php.net/manual/en/function.urlencode.php)。 – jedwards 2014-09-25 20:09:40

回答

2

Try out the urlencode method.

下面是如何使用它的一个例子:

<?php 
$userinput = '"Hello world"'; 
echo '<a href="http://blahblah.com/search/', urlencode($userinput), '">'; 
?> 
+0

在我来到这里之前,这就是我的做法。它不适合我。该链接将在检查中显示编码的字符串,但是当您单击或甚至直接在该栏中输入时,%22全部变回引号。 – wloggains 2014-09-25 20:15:43

+0

什么浏览器和什么版本的浏览器? – Adam 2014-09-25 20:16:12

+0

Chrome和Firefox都是最新版本。 – wloggains 2014-09-25 20:16:36