String replace in xml, makes it invalid?

I have an XML file that has an a repeating invalid line:

<URL> <![CDATA[http://www.whatever.com </URL>

so I thought I could just open it, str_replace (’ </URL’, ‘]]> </URL>’, $line)

but when I write it back to a file, I get:

parser error : Sequence ‘]]>’ not allowed in content

but I need that to close the CDATA, don’t I ?

Been working on this for a few hours, could really use a fresh outlook. Thanks :slight_smile:

It looks like the error occurs because php is trying to parse the xml. Have you tried to echo/save the resulting string without parsing it to see if it looks right?