note 82686 modified in ref.simplexml by danbrown

From: Date: Mon, 18 May 2009 01:11:43 +0000
Subject: note 82686 modified in ref.simplexml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155492@lists.php.net to get a copy of this message
A looked through a lot of the sample code for reading XML files with CDATA, but they didn't work out that well for me. However, I found that the following piece of code worked perfectly for reading through a file using lots of CDATA. <?php $article_string = file_get_contents($path); $article_string = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/', 'filter_xml', $article_string); $article_xml = simplexml_load_string($article_string); function filter_xml($matches) { return trim(htmlspecialchars($matches[1])); } ?> --was-- A looked through a lot of the sample code for reading XML files with CDATA, but they didn't work out that well for me. However, I found that the following piece of code worked perfectly for reading through a file using lots of CDATA. <?php $article_string = file_get_contents($path); $article_string = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/', 'filter_xml', $article_string); $article_xml = simplexml_load_string($article_string); function filter_xml($matches) { return trim(htmlspecialchars($matches[1])); } ?> http://php.net/manual/en/ref.simplexml.php

« previous php.notes (#155492) next »