如下的js代码,如何匹配?
<script>
...
</script>或者有其它办法?

解决方案 »

  1.   

    我用了strpos取得<script>和</script>的位置,然后截取字符串。不知道有没有更好的办法?
      

  2.   

    preg_match("/<script>.+?<\/script>/",$str,$result);
    正则胡写的,不知道行不行。
      

  3.   

    $html = strip_tags($html,"<script>");
      

  4.   

    有必要那么麻烦吗? 
    在<script ......> 后面加个/*
    在</script> 前面加个 */
    或者把这段JS 注释掉 
      

  5.   

    <script>
    js code
    </script>
    这样用正则不能匹配吧?!在我的印象里,正则只能一行一行匹配。不知道有没有理解错?
      

  6.   

    preg_replace("/<script(\\n|\\t|.)*?<\/script>/", "" ,$str)
    终于搞定了。
      

  7.   

    不是这样写的要匹配换行的话,加上/s参数然后,如果你用.*匹配<script>到</script>的话,一不小心就把第一个<script>到最后一个</script>中间全删掉了比如说
    <script>some script</script>here is the html.not script<script>some script</script>这个时候,里面的HTML也不能幸免。一个简陋的正则是这样:
    /<script>.*?<\/script>/sg
      

  8.   

    我不是很赞同。我用/ <script(\\n|\\t|.)*? <\/script>/这个正则“here is the html.not script”不会被删除掉。
    因为/ <script(\\n|\\t|.)*? <\/script>/里面包含<\/script>,就是匹配到第一个</script>标签为止,而不会匹配到
    后面第二、第三……的</script>标签。
    我的说法对吧?!