Help - Search - Member List - Calendar
Full Version: Strip CDATA with regex
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
Johnny Elvers
Hi,

Can sombody here please help me a bit with a regular expression.
I have a xml file where I need to strip the CDATA sections of any
contained data.

Eg.
<xml>
<tag><[CDATA[ some data ]]></tag>
<tag><[CDATA[ some more data ]]></tag>
</xml>

Should end up like this:
<xml>
<tag><[CDATA[]]></tag>
<tag><[CDATA[]]></tag>
</xml>

Now, I have the start and end of the range
([CDATA[)
and
(]]>)

But I cannot figure out how I match any character that is not like the
end of the range.

That is > is ok, ] is ok
but ]]> is not ok.

Thanks in advance,
Balaras

Janwillem Borleffs
Johnny Elvers wrote:
QUOTE
Now, I have the start and end of the range
([CDATA[)
and
(]]>)

But I cannot figure out how I match any character that is not like the
end of the range.


$stripped = preg_replace(
"/<[CDATA[.*]]>/",
"<[CDATA[]]>",
$xml
);


JW


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.