I didn’t hear big announcement of it, but deep in the docs (? PHP 5.1.0) you’ll find a note about additional Libxml parameters. In there you’ll learn about “LIBXML_NOCDATA,” and it works like this:
simplexml_load_string($xmlraw, 'SimpleXMLElement', LIBXML_NOCDATA);
Without that option (and with all previous versions of PHP/SimpleXML), SimpleXML just ignores any < ![CDATA[...]]> ‘escaped’ content, such as you’ll find in most every blog feed.
cdata, cdata in php, fixed, parsing rss, php, php5, rss, simplexml, xml
Posted April 12, 2006 by Casey Bisson
Categories: Technology. Tags: cdata, cdata in php, fixed, parsing rss, php, php5, rss, simplexml, xml.
6 Comments
Comments RSS
TrackBack Identifier URI
User contributed tags for this post:
simplexml cdata (1317) - php simplexml cdata (366) - CDATA simplexml (179) - simplexmlelement cdata (166) - PHP CDATA (75) - simplexml php cdata (46) - simplexml_load_file cdata (45) - simple xml cdata (42) - simplexml load string php4 (42) - LIBXML NOCDATA (41) - cdata php (38) - SimpleXMLElement php4 (32) - LIBXML_NOCDATA (29) - simplexml load string CDATA (28) - cannot parse CDATA (26) - php4 simplexml load string (23) - php LIBXML_NOCDATA (21) - simplexml CDATA php (21) - cdata (21) - simplexml modify (20) - php5 CDATA (19) - php simplexmlelement cdata (19) - cdata simplexml php (19) - simplexml and cdata (19) - F (18) - simplexml ampersand (17) - libxml cdata simplexml (17) - php5 google earth (16) - php parser (16) - preg_replace cdata (16) - php simplexml (15) - simplexml php4 (14) - CDATA in PHP (13) - php xml cdata (13) - simplexml libxml nocdata (12) - simple xml php CDATA (12) - Warning Cannot modify header information headers alread (11) - cdata with simplexml (11) - simplexml php (11) - SimpleXMLElement NOCDATA (10) - simplexml (10) - simple_xml CDATA (9) - SimpleXML LIBXML_NOCDATA (9) - php LIBXML NOCDATA (9) - php simplexml parse line by line (9) - php5 simplexml CDATA (9) - php4 SimpleXMLElement (8) - xml php cdata (8) - cdata in simplexml (8) - php5 header (8) - simplexml_load_file php4 (8) - php5 xml cdata (8) - simpleXML write CDATA (8) - simplexml line break (8) - xml cdata simplexml (8) - simple XML and CDATA (7) - php5 parse RSS (7) - php simplexml write cdata (7) - php simplexml php4 (7) - php simplexml rss (7) - simplexml write (7) - php cdata simplexml (7) - simpleXML modify xml (7) - simplexml flickr output (7) - simplexml with CDATA (7) - php5 RSS (7) - simpleXML line breaks (7) - php5 simplexml (7) - simplexml flickr (6) - cdata and simplexml (6) - php simplexml ![CDATA (6) - php 5 1 cdata rss (6) - php CDATA problem (6) - simplexml modify cdata (6) - php simplexml and cdata (6) - php5 Warning Cannot modify header information headers a (6) - simplexml load string for php4 (6) - how to read CDATA php (6) - php5 header xml (6) - php simple xml cdata (6) - simplexml (6) - simplexml load string post (6) - simplexml nocdata (6) - simplexml_load_file LIBXML_NOCDATA (6) - php simplexml cdata problem (6) - php simplexml_load_file CDATA (6) - CDATA php5 (6) - cdata xml php simplexml (5) - libxml cdata (5) - php simplexml ampersand (5) - simplexml load content in php4 (5) - simplexml et CDATA (5) - php simplexml search (5) - simplexml_load_file INSERT INTO mysql (5) - simplexml rss (5) - simplexml PHP ampersand (5) - php5 xml cdata parse (5) - ampersand simpleXML (5) - simplexml load string cdata error (5) - simplexml php (5) - SimpleXML cdata comment (5) - LIBXML_NOCDATA php (5) - LIBXML NOCDATA php (5) - SimpleXMLElement and cdata (5) - php4 xml cdata (5) - write CDATA Simplexml (4) - CDATA php simplexml (4) - SimpleXMLElement in php4 (4) - SimpleXMLElement load (4) - simplexml output cdata (4) - simplexml load string (4) - regex cdata php (4) - simplexml htmlentities (4) - simplexml ignores CDATA (4) - php output CDATA xml (4) - SimpleXML CDATA Fixed (4) - simplexml cdata problem (4) - SimpleXMLElement insert cdata (4) - php4 simplexml (4) - php4 cdata (4) - php SimpleXML post (4) - Inserting CDATA with simpleXML (4) - simple xml php 5 rss simplexml load string (4) - Simplexml Cannot modify header information (4) - php 4 xml cdata (4) - CDATA content (4) - CDATA xml php (4) - simple xml post php (3) - php5 parse xml cdata (3) - cdata simplexml load string (3) - xml CDATA php (3) - simple xml parse cdata (3) - cdata xml and php4 (3) - php simplexml insert cdata (3) - SimpleXML header php (3) - simplexml_load_file($url, SimpleXMLElement', LIBXML_NOCDATA) (3) - Warning simplexml load string (3) - cdata_to_text (3) - simplexmlelement LIBXML_NOCDATA (3) - php5 to php4 3 (3) - simple xml write cdata (3) - php4 simplexml_load_file() (3) - simplexml c (3) - cdata and php (3) - php nocdata (3) - PHP and CDATA (3) - simplexml for rss parsing (3) - simplexml load CDATA (3) - cdata rss (3) -
I wish more shared hosts would pick up PHP5. All of mine are still using PHP4 and I don’t have access to any of the new XML tools, and I’m afraid to write any thing with PHP4 because they may upgrade and break my scripts. It’s nice to see what there is, even if I can’t use it.
[tags]php5[/tags]
Your comment system has some PHP errors:
WordPress database error: [Duplicate entry '11257-php5' for key 2]
INSERT INTO wp_bsuite_tags (`post_id`,`comment_id`,`tag`,`tag_raw`) VALUES (’11257′, 35263,’php5′, ‘php5′)
Warning: Cannot modify header information – headers already sent by (output started at /home/mais04/public_html/blog/wp-includes/wp-db.php:102) in /home/mais04/public_html/blog/wp-comments-post.php on line 55
Warning: Cannot modify header information – headers already sent by (output started at /home/mais04/public_html/blog/wp-includes/wp-db.php:102) in /home/mais04/public_html/blog/wp-comments-post.php on line 56
Warning: Cannot modify header information – headers already sent by (output started at /home/mais04/public_html/blog/wp-includes/wp-db.php:102) in /home/mais04/public_html/blog/wp-comments-post.php on line 57
Warning: Cannot modify header information – headers already sent by (output started at /home/mais04/public_html/blog/wp-includes/wp-db.php:102) in /home/mais04/public_html/blog/wp-includes/pluggable-functions.php on line 247
[tags]php errors[/tags]
Googled looking for a solution to simpleXml skipping text wrapped in CDATA nodes. Got your page, and tossed in the libXml2 parameter. Worked great! Thanks bud!
thanx a lot for my nerves with this article !
Thanks. This was doing my head in for a couple of hours yesterday. Thought my xml was at fault until i found this article. Glad they’ve fixed it. Its a major oversight otherwise.
For anyone who’s still stuck using PHP 5’s simplexml before v5.1.0 (like me), you can use a fairly simple regex to filter any cdata and collapse them into regular text nodes:
function cdata_to_text($text) {
$result = preg_replace(’/<!\[CDATA\[(.*?)\]\]>/ie’, "htmlentities(’\1′)", $text);
$result = str_replace("\"", """, $result);
return $result;
}