Reputation: 59
in xml file,i am displaying mysql data using php ..In that,i used <![CDATA[ data ]]>
in that some content is coming .some empty tags are there like this "<![CDATA[ ]]>";
i want to remove that all how?
can you please tell me that one.
Upvotes: 0
Views: 3025
Reputation: 178
If you just wish to remove the empty ones, you may use a regular expression replace. See this code for an example.
$xml = "<tags>
<tag><![CDATA[here is content]]></tag>
<tag><![CDATA[ ]]></tag>
</tags>";
$cleanedXml = preg_replace('/<!\[CDATA\[\s*\]\]>/ims', '', $xml);
The output then would be:
<tags>
<tag><![CDATA[here is content]]></tag>
<tag></tag>
</tags>
Hope this helps!
Upvotes: 2