php有办法实现像这样输出js代码?该怎么解决

WBOY
Release: 2016-06-13 10:21:50
Original
719 people have browsed it

php有办法实现像这样输出js代码?
比如有个变量值是这样的

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$a = "<script>window.location.href='http://xxx.com';</script>";
Copy after login


在网页上是直接显示但不执行js:
Assembly code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><script>window.location.href='http://xxx.com';</script>
Copy after login


查看html源文件是这样:
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><script>window.location.href='http://xxx.com';</script>
Copy after login


php有这种函数?还是要怎么转换?

------解决方案--------------------
echo htmlentities($a);
------解决方案--------------------
你这个是网页表单提交的吧?提交处理的代码里有过滤。
------解决方案--------------------
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><div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template