正则替换<script></script>里的内容 rt,要将一个网页源代码中<script></script>中间的内容替换成空格,该如何写啊?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 preg_replace('/<script>(.*)<\/script>/is', ' ', $string); preg_replace("/(<script>)(.*)(<\/script>)/e", "'\\1'.' '.'\\3'", $html_body); preg_replace("/(<script[^>]*?>)(.*)(<\/script>)/e", "'\\1'.' '.'\\3'", $html_body); preg_replace('/<script>([.\s]*)<\/script>/is', ' ', $string); preg_replace('/<script[^>]*>([.\s]*)<\/script>/is', ' ', $string); 另外,为什么不直接弄 <script> ,而是 (<script[^>]*?>) preg_replace('/(?:<script[^>]*>)(.*?)(?:<\/script>)/is', ' ', $string); 你的script标签都肯定没有任何属性的吗?是的话可以直接用<script> preg_replace('/<script.*>([\d\D])<\/script>/i','',$string); 前面的括号 ‘(’里的内容。$pattern = '/<script.*?>(.*?)<\/script>/i';$replacement = "<script> </script>"; $a = preg_replace($pattern, $replacement,$string); 其实script前面还要有\s*因为< script>也是可以运行的。另外有人正则<script[^>]*?>这个问号多余了吧。 \\1是正则第1个括号里的内容,\\3是正则第3个括号的内容不直接弄 <script> ,而是 (<script[^>]*?>)是因为并不是所有的script开始标记都只有<script>。还有可能会有<script language='***'>或其他什么 只知道跟output_buffering有关系,不知道具体怎么做。 php中删除数据库中不匹配的记录 关于session PHP模糊查询 类似csdn社区这种框架结构的网页刷新问题 关于这段代码中的save_node 求HTML在線編輯器,功能只需要字體可改大小和顏色就行啦 --------有没有什么完善的文章系统,帮忙推荐一个。。。。------- 请教有关php_exif的问题。急,在线等。 将16进制转换成10进制整数 现在模板\程序\数据库都是UTF-8了,可还是乱码。。。 c/c++拓展php
另外,为什么不直接弄 <script> ,而是 (<script[^>]*?>)
前面的括号 ‘(’里的内容。
$pattern = '/<script.*?>(.*?)<\/script>/i';
$replacement = "<script> </script>";
$a = preg_replace($pattern, $replacement,$string);
另外有人正则<script[^>]*?>这个问号多余了吧。
还有可能会有<script language='***'>或其他什么