我从URL中获得了$ _GET [q]。我正在尝试将搜索词回显到搜索框中。有时人们可能会提交用引号括起来的查询,在这种情况下,ECHO会解释搜索词
ECHO $_GET[q];
为:
ECHO ""search term"";
,结果我得到一个空白的搜索框。用单引号搜索查询,例如:Peter的房子,工作正常。
当我使用时:
mysqli_real_escape_string($conn, $_GET[q])
我在搜索框中只得到一个反斜杠。
如何用双引号括起来的搜索词填充搜索框?
答案 0 :(得分:1)
答案 1 :(得分:1)
您还可以使用:
echo str_replace('"','',$_GET[q]);
这当然会删除所有双引号,因此,如果它们在搜索词中的某处可能有效,那么最好是:
echo str_replace('"','"',$_GET[q]);
尚未对此进行测试,但这也可能有效:
echo html_entity_decode(htmlentities($_GET[q))
答案 2 :(得分:1)
您可以尝试:
$str = "Hello World!";
echo $str . "<br>";
echo chop($str,"");
输出量:
Hello World
说明:
chop()
函数可帮助您剔除任何可能添加到字符串中的引号。
您可以根据自己的代码进行适当的操作。
答案 3 :(得分:1)
$str = preg_replace( '["|\']','', $_REQUEST['q'] );
echo( $str ); //no double, no single quotes, faster than str_replace when you have to make more than 1 call to str_replace
或...
$str = str_replace( '"','', $_REQUEST['q'] ); //no double quotes, faster than preg_replace when you only make one call to str_replace
echo( $str ); //no double quotes