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

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

问题描述:

How can I find a element in a string with the php function strpos. I get a parse error whenever I execute the function with the $error string.

[Symfony\Component\Debug\Exception\FatalErrorException] parse error

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

You have multiple errors, your $error string is not a valid string. You are also missing the $ from str in your echo.

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