Is php capable of outputting js code like this? How can this problem be solved?

Source: Internet
Author: User
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》

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.