php 过滤JS问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:49:09
<?php
$content = file_get_contents("http://www.700la.com/");
$of = fopen('700.htm','w');
if($of){
fwrite($of,$content);
}
fclose($of);
?>

这个是读取网站的html 并保存到本地为 700.htm

怎样将保存的代码里面的以下内容过滤掉 不含引号
“document.write('”
“\”
“');”

比如内容为
document.write('<a href=\'http://www.700la.com\' title=\'123\' target=\'_blank\'>123</a>');
保存到本地后则显示
<a href='http://www.700la.com' title='123' target='_blank'>123</a>

正则表达式加反转义引号
code:
<?php
$string=stripcslashes("document.write('<a href=\'http://www.700la.com\' title=\'123\' target=\'_blank\'>123</a>');");
echo $string."\n";
echo preg_replace("/document.write\((?:\'|\")(.*)(?:\'|\")\);/i","$1", $string);
?>

output:
---------- php ----------
document.write('<a href='http://www.700la.com' title='123' target='_blank'>123</a>');
<a href='http://www.700la.com' title='123' target='_blank'>123</a>
输出完成 (耗时: 0 秒) - 正常终止

php中嵌入js问题 js字符过滤 请教 关于php中使用js问题,急。。。 js 调用 php php返回值 js 过滤问题 js如何调用php变量 php js 按规律刷新 JS过滤HTML代码应该怎么写 我想在JS内写个判断过滤字符串