Hi all,
I need to parse an XML file, which includes CDATA and HTML <br> tag I would like to include for my output.
I would like to replace <br> with <br /><br /> - Two spaces, but it doesnt seem to happen.
This is an example on the XML file, and how I am parsing it. Is there another way so that I can simple output the data, and not replace anything. (But I would like to replace <br> with two <br /><br /> still..)
XML file:
<body>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
<![CDATA[
TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT. TEXT TEXT.
]]>
<br/>
</body>
I am getting the data like this, works fine - But I am not sure if I am doing it the smartest way - And as mentioned, I would like to replace br with two line breaks form the xml file.
if($XML_file = @simplexml_load_file($XML_url))
{
$data = str_replace(array('<![CDATA[', ']]>'), array('',''), $XML_file->asXML());
}
else $data = '';
return $data;
That returns the data, with line breaks <br> - But I cant seem to replace <br> with to <br /> when I use the returned data from another variable outside the method.
Any comments on another approach to parse XML file with simplexml, that includes CDATA?
Regards, Klemme