How to remove `//<![CDATA[` and end `//]]>`?

bomanden picture bomanden · Nov 27, 2011 · Viewed 38.1k times · Source

How can I remove the (//<![CDATA[ , //]]>) blocks; tags inside a script element.

<script type="text/javascript">
    //<![CDATA[
    var l=new Array();
    ..........................
    ..........................
    //]]>
</script>

Looks like it can be done with preg_replace() but havent found a solution that works for me.

What regex would I use?

Answer

Dimme picture Dimme · Nov 27, 2011

You don't need regex for a static string.

Replace those parts of the texts with nothing:

$string = str_replace("//<![CDATA[","",$string);
$string = str_replace("//]]>","",$string);