使用strpos |查找String中的script元素PHP

时间:2017-09-10 15:23:59

标签: php

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

  

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

 $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;
                }

1 个答案:

答案 0 :(得分:1)

您有多个错误,您的$字符串不是有效字符串。你的回音中也错过了来自str的{​​{1}}。

<?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;
}