Is php capable of outputting js code like this? For example, the variable value is PHPcode $ a = & quot; & lt; script & gt; window. location. href = 'http: // xxx.com '; & lt;/script & gt; & quot ;; is it directly displayed on the webpage, but does not execute j php? is there a way to output js code like this?
For example, a variable value is like this.
PHP code
$a = "《script》window.location.href='http://xxx.com';《script》";
The webpage is directly displayed but js is not executed:
Assembly code
《script》window.location.href='http://xxx.com';《script》
View the html source file as follows:
HTML code
《script》window.location.href='http://xxx.com';《script》
Does php have such a function? Or how to convert it?
------ Solution --------------------
Echo htmlentities ($ );
------ Solution --------------------
Are you submitting a webpage form? The code submitted for processing contains filtering.
------ Solution --------------------
PHP code
$a = "《script》window.location.href='http://xxx.com';《script》";$b = htmlspecialchars($a);echo $b;//result: 《script》window.location.href='http://xxx.com';《script》 //source: 《script》window.location.href='http://xxx.com';《script》