正则替换<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='***'>或其他什么 求php的分割标题 并且保存到某字段中的代码 关于php邮件问题! php中 == 和 === 有什么区别? 帮忙解决下数组的问题!(菜鸟问..) linux apache服务器,上传的中文图片用url访问不到 关于php远程连接ORACLE的问题 可以输入的下拉菜单[共享] ===GD 的配置 为啥我搞不定=== php的文件操作问题? 现在国内用PHP技术的公司多不多呀? 现在模板\程序\数据库都是UTF-8了,可还是乱码。。。 c/c++拓展php
另外,为什么不直接弄 <script> ,而是 (<script[^>]*?>)
前面的括号 ‘(’里的内容。
$pattern = '/<script.*?>(.*?)<\/script>/i';
$replacement = "<script> </script>";
$a = preg_replace($pattern, $replacement,$string);
另外有人正则<script[^>]*?>这个问号多余了吧。
还有可能会有<script language='***'>或其他什么