Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用strpos | PHP在字符串中查找脚本元素_Php - Fatal编程技术网

使用strpos | PHP在字符串中查找脚本元素

使用strpos | PHP在字符串中查找脚本元素,php,Php,如何使用php函数strpos在字符串中查找元素。每当我使用$error字符串执行函数时,我都会得到一个解析错误 [Symfony\Component\Debug\Exception\FatalErrorException]分析错误 $error='您的SQL语法有错误; 检查与MySQL服务器版本对应的手册 对于要使用的正确语法 “=第1行的警报('o7v87r99ib')”; $str='=警报('o7v87r99ib'); if(strpos($error,$str)){ echo“Fou

如何使用php函数
strpos
在字符串中查找元素。每当我使用$error字符串执行函数时,我都会得到一个解析错误

[Symfony\Component\Debug\Exception\FatalErrorException]分析错误

$error='您的SQL语法有错误;
检查与MySQL服务器版本对应的手册
对于要使用的正确语法
“=第1行的警报('o7v87r99ib')”;
$str='=警报('o7v87r99ib');
if(strpos($error,$str)){
echo“Found:”.$str;
}

您有多个错误,您的
$error
字符串不是有效的字符串。您的echo中还缺少
str
中的
$

<?php
 $error =  'You have an error in your SQL syntax;            
           check the manual that corresponds to your MySQL server version    
           for the right syntax to use near 
           \'"=<script>alert(\'o7v87r99ib\')</script>"\' at line 1';

$str = "=<script>alert('o7v87r99ib')</script>";

if(strpos($error, $str)){
    echo 'Found: ' .$str;
}

突出显示的语法将显示您的错误并转义引号:
$str='=alert(\'o7v87r99ib\')完全正确。重写$str='=alert('o7v87r99ib');至$str=“=警报('o7v87r99ib')”@johncode我知道错误的原因,但我不知道解决方法。
$error
字符串也是如此。把你的报价也整理一下。
<?php
 $error =  'You have an error in your SQL syntax;            
           check the manual that corresponds to your MySQL server version    
           for the right syntax to use near 
           \'"=<script>alert(\'o7v87r99ib\')</script>"\' at line 1';

$str = "=<script>alert('o7v87r99ib')</script>";

if(strpos($error, $str)){
    echo 'Found: ' .$str;
}