如何删除`//<![CDATA [`and end`//]]>`? [英] How to remove `//<![CDATA[` and end `//]]>`?
本文介绍了如何删除`//<![CDATA [`and end`//]]>`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除(//<![CDATA[ , //]]>
)块; script
元素内的标签.
How can I remove the (//<![CDATA[ , //]]>
) blocks; tags inside a script
element.
<script type="text/javascript">
//<![CDATA[
var l=new Array();
..........................
..........................
//]]>
</script>
看起来可以用preg_replace()
完成,但还没有找到适合我的解决方案.
Looks like it can be done with preg_replace()
but havent found a solution that works for me.
我将使用什么正则表达式?
What regex would I use?
推荐答案
以下正则表达式可以做到...
The following regex will do it...
$removed = preg_replace('/^\s*\/\/<!\[CDATA\[([\s\S]*)\/\/\]\]>\s*\z/',
'$1',
$scriptText);
CodePad .
这篇关于如何删除`//<![CDATA [`and end`//]]>`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文