首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

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

2012-05-11 
php有办法实现像这样输出js代码?比如有个变量值是这样的PHP code$a scriptwindow.location.hrefhtt

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

PHP code
$a = "<script>window.location.href='http://xxx.com';</script>";


在网页上是直接显示但不执行js:
Assembly code
<script>window.location.href='http://xxx.com';</script>


查看html源文件是这样:
HTML code
&lt;script&gt;window.location.href='http://xxx.com';&lt;/script&gt;


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: &lt;script&gt;window.location.href='http://xxx.com';&lt;/script&gt; 

热点排行