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

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

WBOY
WBOYOriginal
2016-06-13 10:21:50719browse

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

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


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


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


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>
Statement:
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