Php 块;和';从输入字段中输入

Php 块;和';从输入字段中输入,php,string,Php,String,我得到了这么简单的代码: private function edit_keywords($text) { $tresc = str_replace("\n","",$text); $tresc = str_replace("\r","",$text); if(strpos($text,'"')!==FALSE) { array_push($this->warnings,"Not allowed character found in k

我得到了这么简单的代码:

    private function edit_keywords($text)
{
    $tresc = str_replace("\n","",$text);
    $tresc = str_replace("\r","",$text);
    if(strpos($text,'"')!==FALSE)
    {
        array_push($this->warnings,"Not allowed character found in keywords \".");
        return;
    }
目前这将阻止输入“”,我也想阻止“”。怎么做


替换“也可以。

您可以编写第二个
strpos
检查单引号,可以使用双引号(
”)或通过转义单引号:
\'

最终,您可能会达到这样的复杂程度:您希望在数组中存储所有要测试的字符,并对它们进行迭代,而不是不断追加新的
if
语句:

$bad_chars = array('"', '\'');

foreach ($bad_chars as $bad_char) {
  if (strpos($text, $bad_char) !== false) {
    array_push($this->warnings,"Not allowed character found in keywords \".");
    return; # or break, to stop after the first disallowed characte
  }
}

试试这个:

<?php

private function edit_keywords($text)
{
    $tresc = str_replace("\n","",$text);
    $tresc = str_replace("\r","",$text);

    if ((strpos($text,'"')!==FALSE)||(strpos($text,"'")!==FALSE))
    {
        array_push($this->warnings,"Not allowed character found in keywords \".");
        return;
    }

?>

这是对允许字符的一个非常奇怪的限制。为什么你只是禁止ASCII中的引号字符?我不知道该怎么说。你有检查
”的代码,你不能用它来检查
?您有替换
\n
\r
的代码,不能使用相同的代码替换
'
?请记住:所有客户端检查都很容易绕过,因此必须在server@Adam他正在检查服务器端。@meagar哦,对了。我最近一直在看很多客户端JS验证,所以我的想法是错误的,我认为你的逻辑and(
&&
)应该是OR(
|
),你肯定想要一个| |,而不是&&&&@AdamBatkin ooops!对。刚刚修好了!:-)
<?php

private function edit_keywords($text)
{
    $tresc = str_replace("\n","",$text);
    $tresc = str_replace("\r","",$text);

    if ((strpos($text,'"')!==FALSE)||(strpos($text,"'")!==FALSE))
    {
        array_push($this->warnings,"Not allowed character found in keywords \".");
        return;
    }

?>