©
本文档使用
php.cn手册 发布
[#1] Serge [2015-02-26 22:58:55]
XML data values should not contain "&" and that need to be replaced by html-entity "&"
You can use this code to replace lonely "&" to "&":
<?php
$sText = preg_replace('#&(?![a-z]{1,6};)#i', '&', $sText);
?>
This will replace just "&" into "&" but dont touches other html-entities like " ", "<" etc and, of course, "&".
P.S. In regexp max length is 6 becouse I found that is the maximum length of possible html entity using this code:
<?php
max(array_map('strlen', array_values(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5)))) - 2
?>
minus two is for first "&" and last ";" in an any html entity.
[#2] Tim Adam Perez [2014-01-23 20:22:45]
XML to Array in a single line:
$array = (array) simplexml_load_string($xml);
Enjoy!
[#3] maikel at yuluma dot com [2013-10-17 09:02:51]
In reply to soloman at textgrid dot com,
2 line XML2Array:
$xml = simplexml_load_string($file);
$array = (array)$xml;
[#4] dkrnl at yandex dot ru [2013-09-30 02:57:35]
Wrapper XMLReader class, for simple SAX-reading huge xml:
https://github.com/dkrnl/SimpleXMLReader
Usage example: http://github.com/dkrnl/SimpleXMLReader/blob/master/examples/example1.php
<?php
class SimpleXMLReader extends XMLReader
{
protected $callback = array();
public function registerCallback($name, $callback, $nodeType = XMLREADER::ELEMENT)
{
if (isset($this->callback[$nodeType][$name])) {
throw new Exception("Already exists callback $name($nodeType).");
}
if (!is_callable($callback)) {
throw new Exception("Already exists parser callback $name($nodeType).");
}
$this->callback[$nodeType][$name] = $callback;
return $this;
}
public function unRegisterCallback($name, $nodeType = XMLREADER::ELEMENT)
{
if (!isset($this->callback[$nodeType][$name])) {
throw new Exception("Unknow parser callback $name($nodeType).");
}
unset($this->callback[$nodeType][$name]);
return $this;
}
public function parse()
{
if (empty($this->callback)) {
throw new Exception("Empty parser callback.");
}
$continue = true;
while ($continue && $this->read()) {
if (isset($this->callback[$this->nodeType][$this->name])) {
$continue = call_user_func($this->callback[$this->nodeType][$this->name], $this);
}
}
}
public function expandXpath($path, $version = "1.0", $encoding = "UTF-8")
{
return $this->expandSimpleXml($version, $encoding)->xpath($path);
}
public function expandString($version = "1.0", $encoding = "UTF-8")
{
return $this->expandSimpleXml($version, $encoding)->asXML();
}
public function expandSimpleXml($version = "1.0", $encoding = "UTF-8", $className = null)
{
$element = $this->expand();
$document = new DomDocument($version, $encoding);
$node = $document->importNode($element, true);
$document->appendChild($node);
return simplexml_import_dom($node, $className);
}
public function expandDomDocument($version = "1.0", $encoding = "UTF-8")
{
$element = $this->expand();
$document = new DomDocument($version, $encoding);
$node = $document->importNode($element, true);
$document->appendChild($node);
return $document;
}
}
?>
[#5] Anonymous [2013-06-26 16:23:33]
<?phpxml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
<Default Extension="xml" ContentType="application/xml" />
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" />
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
<Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" />
<Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml" />
<Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" />
<Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml" />
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
</Types>
[#6] whyme [2012-12-28 21:55:18]
Simple means simple. If you know the structure and just want the value of a tag:
<?php
$xml = simplexml_load_file($xmlfile);
print $xml->City->Street->Address->HouseColor;
?>
Warning, numbers can come out as strings, empty elements like <HouseColor></HouseColor> come out as array(0)
[#7] Laurent Vervisch [2012-06-24 10:57:20]
Here is an example of an easy mapping between xml and classes defined by user.
<?php
class XmlClass extends SimpleXMLElement
{
public function asInstanceOf($class_name)
{
// should check that class_name is valid
return simplexml_import_dom(dom_import_simplexml($this), $class_name);
}
public function __call($name, array $arguments)
{
echo "magic __call called for method $name on instance of ".get_class()."\n";
// class could be mapped according $this->getName()
$class_name = 'Test';
$instance = $this->asInstanceOf($class_name);
return call_user_func_array(array($instance, $name), $arguments);
}
}
class Test extends XmlClass
{
public function setValue($string)
{
$this->{0} = $string;
}
}
$xml = new XmlClass('<example><test/></example>');
$test = $xml->test->asInstanceOf('Test');
echo get_class($xml->test), "\n";
echo get_class($test), "\n";
$test->setValue('value set directly by instance of Test');
echo (string)$xml->test, "\n";
echo (string)$test, "\n";
$xml->test->setValue('value set by instance of XmlClass and magic __call');
echo (string)$xml->test, "\n";
echo (string)$test, "\n";
?>
XmlClass
Test
value set directly by instance of Test
value set directly by instance of Test
magic __call called for method setValue on instance of XmlClass
value set by instance of XmlClass and magic __call
value set by instance of XmlClass and magic __call
[#8] xaviered at gmail dot com [2012-05-17 19:00:19]
Here is a recursive function that will convert a given SimpleXMLElement object into an array, preserving namespaces and attributes.
<?php
function xmlObjToArr($obj) {
$namespace = $obj->getDocNamespaces(true);
$namespace[NULL] = NULL;
$children = array();
$attributes = array();
$name = strtolower((string)$obj->getName());
$text = trim((string)$obj);
if( strlen($text) <= 0 ) {
$text = NULL;
}
// get info for all namespaces
if(is_object($obj)) {
foreach( $namespace as $ns=>$nsUrl ) {
// atributes
$objAttributes = $obj->attributes($ns, true);
foreach( $objAttributes as $attributeName => $attributeValue ) {
$attribName = strtolower(trim((string)$attributeName));
$attribVal = trim((string)$attributeValue);
if (!empty($ns)) {
$attribName = $ns . ':' . $attribName;
}
$attributes[$attribName] = $attribVal;
}
// children
$objChildren = $obj->children($ns, true);
foreach( $objChildren as $childName=>$child ) {
$childName = strtolower((string)$childName);
if( !empty($ns) ) {
$childName = $ns.':'.$childName;
}
$children[$childName][] = xmlObjToArr($child);
}
}
}
return array(
'name'=>$name,
'text'=>$text,
'attributes'=>$attributes,
'children'=>$children
);
}
?>
[#9] thedoc8786 at gmail dot com [2012-03-23 19:42:16]
FAIL! This function works better than the one I posted below:
<?php
function toArray($xml) {
$array = json_decode(json_encode($xml), TRUE);
foreach ( array_slice($array, 0) as $key => $value ) {
if ( empty($value) ) $array[$key] = NULL;
elseif ( is_array($value) ) $array[$key] = toArray($value);
}
return $array;
}
[#10] thedoc8786 at gmail dot com [2012-03-23 16:19:04]
I know it is over-done, but the following is a super-short example of a XML to Array conversion function (recursive):
<?php
function toArray(SimpleXMLElement $xml) {
$array = (array)$xml;
foreach ( array_slice($array, 0) as $key => $value ) {
if ( $value instanceof SimpleXMLElement ) {
$array[$key] = empty($value) ? NULL : toArray($value);
}
}
return $array;
}
[#11] xananax at yelostudio dot com [2011-09-07 18:25:32]
None of the XML2Array functions that I found satisfied me completely; Their results did not always fit the project I was working on, and I found none that would account for repeating XML elements (such as
<fields><field/><field/><field/></fields>)
So I rolled out my own; hope it helps someone.
<?php
function simpleXMLToArray(SimpleXMLElement $xml,$attributesKey=null,$childrenKey=null,$valueKey=null){
if($childrenKey && !is_string($childrenKey)){$childrenKey = '@children';}
if($attributesKey && !is_string($attributesKey)){$attributesKey = '@attributes';}
if($valueKey && !is_string($valueKey)){$valueKey = '@values';}
$return = array();
$name = $xml->getName();
$_value = trim((string)$xml);
if(!strlen($_value)){$_value = null;};
if($_value!==null){
if($valueKey){$return[$valueKey] = $_value;}
else{$return = $_value;}
}
$children = array();
$first = true;
foreach($xml->children() as $elementName => $child){
$value = simpleXMLToArray($child,$attributesKey, $childrenKey,$valueKey);
if(isset($children[$elementName])){
if(is_array($children[$elementName])){
if($first){
$temp = $children[$elementName];
unset($children[$elementName]);
$children[$elementName][] = $temp;
$first=false;
}
$children[$elementName][] = $value;
}else{
$children[$elementName] = array($children[$elementName],$value);
}
}
else{
$children[$elementName] = $value;
}
}
if($children){
if($childrenKey){$return[$childrenKey] = $children;}
else{$return = array_merge($return,$children);}
}
$attributes = array();
foreach($xml->attributes() as $name=>$value){
$attributes[$name] = trim($value);
}
if($attributes){
if($attributesKey){$return[$attributesKey] = $attributes;}
else{$return = array_merge($return, $attributes);}
}
return $return;
}
?>
[#12] soloman at textgrid dot com [2011-08-09 17:06:55]
Three line xml2array:
<?php
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
?>
Ta da!
[#13] streaver91 at gmail dot com [2011-05-04 20:49:20]
The BIGGEST differece between an XML and a PHP array is that in an XML file, the name of elements can be the same even if they are siblings, eg. "<pa><ch /><ch /><ch /></pa>", while in an PHP array, the key of which must be different.
I think the array structure developed by svdmeer can fit for XML, and fits well.
here is an example array converted from an xml file:
array(
"@tag"=>"name",
"@attr"=>array(
"id"=>"1","class"=>"2")
"@text"=>"some text",
)
or if it has childrens, that can be:
array(
"@tag"=>"name",
"@attr"=>array(
"id"=>"1","class"=>"2")
"@items"=>array(
0=>array(
"@tag"=>"name","@text"=>"some text"
)
)
Also, I wrote a function that can change that array back to XML.
<?php
<{$root}></{$root}>");
function array2XML($arr,$root) {
$xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\" ?>
$f = create_function('$f,$c,$a','
foreach($a as $v) {
if(isset($v["@text"])) {
$ch = $c->addChild($v["@tag"],$v["@text"]);
} else {
$ch = $c->addChild($v["@tag"]);
if(isset($v["@items"])) {
$f($f,$ch,$v["@items"]);
}
}
if(isset($v["@attr"])) {
foreach($v["@attr"] as $attr => $val) {
$ch->addAttribute($attr,$val);
}
}
}');
$f($f,$xml,$arr);
return $xml->asXML();
}
?>
[#14] phil at dier dot us [2011-01-19 11:37:11]
Here's a function I came up with to convert an associative array to XML. Works for multidimensional arrays as well.
<?php
<{$root_element_name}></{$root_element_name}>");
function assocArrayToXML($root_element_name,$ar)
{
$xml = new SimpleXMLElement("<?xml version=\"1.0\"?>
$f = create_function('$f,$c,$a','
foreach($a as $k=>$v) {
if(is_array($v)) {
$ch=$c->addChild($k);
$f($f,$ch,$v);
} else {
$c->addChild($k,$v);
}
}');
$f($f,$xml,$ar);
return $xml->asXML();
}
?>
[#15] philipp at strazny dot com [2010-11-23 17:33:51]
Here's a quick way to dump the nodeValues from SimpleXML into an array using the path to each nodeValue as key. The paths are compatible with e.g. DOMXPath. I use this when I need to update values externally (i.e. in code that doesn't know about the underlying xml). Then I use DOMXPath to find the node containing the original value and update it.
<?php
function XMLToArrayFlat($xml, &$return, $path='', $root=false)
{
$children = array();
if ($xml instanceof SimpleXMLElement) {
$children = $xml->children();
if ($root){ // we're at root
$path .= '/'.$xml->getName();
}
}
if ( count($children) == 0 ){
$return[$path] = (string)$xml;
return;
}
$seen=array();
foreach ($children as $child => $value) {
$childname = ($child instanceof SimpleXMLElement)?$child->getName():$child;
if ( !isset($seen[$childname])){
$seen[$childname]=0;
}
$seen[$childname]++;
XMLToArrayFlat($value, $return, $path.'/'.$child.'['.$seen[$childname].']');
}
}
?>
Use like this:
<?php
$xml = simplexml_load_string(...some xml string...);
$xmlarray = array(); // this will hold the flattened data
XMLToArrayFlat($xml, $xmlarray, '', true);
?>
You can also pull multiple files in one array:
<?php
foreach($files as $file){
$xml = simplexml_load_file($file);
XMLToArrayFlat($xml, $xmlarray, $file.':', true);
}
?>
The respective filename/path is thus prefixed to each key.
[#16] kristof at viewranger dot com [2010-11-18 05:14:40]
If you tried to load an XML file with this, but the CDATA parts were not loaded for some reason, is because you should do it this way:
$xml = simplexml_load_file($this->filename, 'SimpleXMLElement', LIBXML_NOCDATA);
This converts CDATA to String in the returning object.
[#17] sherwinterunez at yahoo dot com [2010-09-01 11:15:23]
<?php
// Sherwin R. Terunez
//
// This is my own version of XML Object to Array
//
function amstore_xmlobj2array($obj, $level=0) {
$items = array();
if(!is_object($obj)) return $items;
$child = (array)$obj;
if(sizeof($child)>1) {
foreach($child as $aa=>$bb) {
if(is_array($bb)) {
foreach($bb as $ee=>$ff) {
if(!is_object($ff)) {
$items[$aa][$ee] = $ff;
} else
if(get_class($ff)=='SimpleXMLElement') {
$items[$aa][$ee] = amstore_xmlobj2array($ff,$level+1);
}
}
} else
if(!is_object($bb)) {
$items[$aa] = $bb;
} else
if(get_class($bb)=='SimpleXMLElement') {
$items[$aa] = amstore_xmlobj2array($bb,$level+1);
}
}
} else
if(sizeof($child)>0) {
foreach($child as $aa=>$bb) {
if(!is_array($bb)&&!is_object($bb)) {
$items[$aa] = $bb;
} else
if(is_object($bb)) {
$items[$aa] = amstore_xmlobj2array($bb,$level+1);
} else {
foreach($bb as $cc=>$dd) {
if(!is_object($dd)) {
$items[$obj->getName()][$cc] = $dd;
} else
if(get_class($dd)=='SimpleXMLElement') {
$items[$obj->getName()][$cc] = amstore_xmlobj2array($dd,$level+1);
}
}
}
}
}
return $items;
}
?>
[#18] michael dot allen at emp dot shentel dot com [2010-04-15 11:06:22]
Here is a very robust SimpleXML parser. Can be used to load files, strings, or DOM into SimpleXML, or can be used to perform the reverse when handed SimpleXML.
<?php
class XMLParser {
public static function loadFile($doc) {
if (file_exists($doc)) {
return simplexml_load_file($doc);
} else {
throw new Exception ("Unable to load the xml file " .
"using: \"$doc\"", E_USER_ERROR);
}
}
public static function loadString($string) {
if (isset($string)) {
return simplexml_load_string($string);
} else {
throw new Exception ("Unable to load the xml string " .
"using: \"$string\"", E_USER_ERROR);
}
}
public static function loadDOM($dom) {
if (isset($dom)) {
return simplexml_import_dom($dom);
} else {
throw new Exception ("Unable to load the xml DOM node " .
"using: \"$dom\"", E_USER_ERROR);
}
}
public static function loadSXML($simplexml, $type, $path) {
if (isset($simplexml) && isset($type)) {
switch ($type) {
case 'string':
return $simplexml->asXML();
break;
case 'file':
if (isset($path)) {
return $simplexml->asXML($path);
} else {
throw new Exception ("Unable to create the XML file. Path is missing or" .
"is invalid: \"$path\"", E_USER_ERROR);
}
break;
case 'dom':
return dom_import_simplexml($simplexml);
break;
}
} else {
throw new Exception ("Unable to load the simple XML element " .
"using: \"$simplexml\"", E_USER_ERROR);
}
}
}
?>
[#19] emmanuel [2010-02-17 10:21:24]
dynamic sql in php using xml:
test.xml:
<?phpxml version="1.0" encoding="UTF-8"?>
<sql>
<statement>
SELECT * FROM USERS
<call criteria="byId">WHERE id = %d</call>
<call criteria="byUsername">WHERE username = "%s"</call>;
</statement>
</sql>
index.php:
<?php
function callMe($param) {
$search = array('byUsername' => 'dynsql');
if (isset($search[$param[1]])) {
return sprintf($param[2], $search[$param[1]]);
}
return "";
}
$xml = simplexml_load_file("test.xml");
$string = $xml->statement->asXML();
$string = preg_replace_callback('/<call criteria="(\w+)">(.*?)<\/call>/', 'callMe', $string);
$node = simplexml_load_string($string);
echo $node;
?>
obviously, this example can be improved [in your own code.]
[#20] mahmutta at gmail dot com [2010-01-20 12:58:40]
while using simple xml and get double or float int value from xml object for using math operations (+ * - / ) some errors happens on the operation, this is because of simple xml returns everythings to objects.
exmple;
<?php
$name = "somestring";
$size = 11.45;
$xml = '
<xml>
<name>somestring</name>
<size>11.45</size>
</xml>';
$xmlget = simplexml_load_string($xml)
echo $xml->size*2; // 20 its false
// ($xml->size is an object (int)11 and (45) )
// this is true
echo $size*2; // 22.90
echo (float)$size*2; // 22.90
?>
[#21] Danny from holland [2009-12-03 05:58:30]
I tested all the scripts ive found on this page but none of them wasnt working.
ive made an new script that will work and wont get any memory errors with big xml feeds
<?php
print "<pre>";
$root = simplexml_load_string($XML_URL);
$data = get_object_vars($root);
$producten = array();
foreach ($data['product'] as $keys => $values) {
$producten['product'][$keys] = get_object_vars($data['product']);
foreach ($values as $key => $value) {
$value = str_replace("\r\n", '<br />', $value);
$value = str_replace("\r", '<br />', $value);
$value = str_replace("\n", '<br />', $value);
$producten['product'][$keys][$key] = $value;
}
}
print_R($producten);
print "</pre>";
?>
[#22] antoine dot rabanes at gmail dot com [2009-10-16 07:22:00]
if for some reasons you need the string value instead of the simpleXML Object you can cast the return value as a string.
exemple:
<?php
$all_api_call = simplexml_load_file($url);
$all_api = array();
$all_api = $all_api_call->result;
$list_all_api_name = array();
$i = 0;
foreach ($all_api->children() as $funcky_function)
{
$string_tmp = (string )$funcky_function->function;
$list_all_api_name[$i++] = $putain;
}
?>
...
[#23] walter [2009-06-12 07:58:21]
Working fix for the infamous SimpleXML + memcache bug.
Improves code at http://tinyurl.com/bmoon-simplexml to actually work for arbitrary-depth structures. (Because neither the function nor the json_decode(json_encode($obj)) hack listed there worked for me.)
There's probably some superfluous code in here that could be improved on -- but it works!
<?php
# convert a structure that may include objects to a pure
# array-based structure (that can be stored in memcache)
# ... includes support for simplexml!
# (nb: may have problems with infinite recursive structs)
function enforce_array($obj) {
$array = (array)$obj;
if(empty($array)) {
$array = '';
}
else {
foreach($array as $key=>$value) {
if(!is_scalar($value)) {
if(is_a($value,'SimpleXMLElement')) {
$tmp = memcache_objects_to_array($value);
if(!is_array($tmp)) {
$tmp = ''.$value;
}
$array[$key] = $tmp;
}
else {
$array[$key] = enforce_array($value);
}
}
else {
$array[$key] = $value;
}
}
}
return $array;
}
?>
[#24] mail at kleineedv dot de [2009-04-28 00:37:29]
I had a problem with simplexml reading nodes from an xml file. It always return an SimpleXML-Object but not the text inside the node.
Example:
<?phpxml version="1.0" encoding="UTF-8"?>
<Test>
<Id>123</Id>
</Test>
Reading this xml into a variable called $xml and then doing the following
<?php
$myId = $xml->Id;
?>
Did not return 123 in $myId, but instead I got a SimpleXMLElement Object.
The solution is simple, when you know it. Use explicit string conversion.
<?php
$myId = (string)$xml->Id;
?>
[#25] oscargodson at gmail dot com [2009-01-25 03:05:10]
To add to what others have said, you can't directly put a $_GET or $_POST value into a variable then into an attribute using SimpleXML. You must first convert it to an integer.
This will NOT work
<?php
$page_id = $_GET['id'];
echo $xml->page[$page_id]
?>
You will get something like:
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/mysite/index.php on line 10
However, this WILL work and is much simpler then using (string) or other methods.
<?php
$page_id = intval($_GET['id']);
echo $xml->page[$page_id]
?>
[#26] bxt at die-optimisten dot net [2008-11-26 07:47:43]
Addition to QLeap's post:
SimpleXML will return a reference to an object containing the node value and you can't use references in session variables as there is no feasible way to restore a reference to another variable.
This won't work too:
$val=$this->xml->node->attributes()->name;
echo $array[$val]; // will cause a warning because of the wrong index type.
You have to convert/cast to a String first:
echo $array[(string)$val];
This will work as expected, because converting will call the __toString() method. Therefor echo works too:
echo $val; // will display the name
[#27] QLeap [2008-11-18 14:27:21]
Storing SimpleXMLElement values in $_SESSION does not work. Saving the results as an object or individual elements of the object will result in the dreaded "Warning: session_start() [function.session-start]: Node no longer exists" error.
For example, this does not work:
$xml = new SimpleXMLElement($page);
$country = $xml->Response->Placemark->AddressDetails->Country->CountryNameCode;
$_SESSION['country'] = $country;
This will work:
$_SESSION['country'] = (string) $country;
[#28] gwhitescarver at yahoo dot com [2008-09-11 13:02:32]
Moving some code from a PHP 5.2.6 / Windows environment to a 5.2.0 / Linux environment, I somehow lost access to a plain text node within a SimpleXML Object. On a var_dump of $xml_node, a [0] element was shown as the string '12'. However, $xml_node[0] was evaluating NULL in 5.2.0. You can see below the code change I made, pulling my data out of the raw XML with a regular expression. Hope this is useful to someone.
//In some versions of PHP it seems we cannot access the [0] element of a SimpleXML Object. Doesn't work in 5.2.0:
//$count = $xml_node[0];
//grab the raw XML:
$count = ($xml_node->asXML());
//pull out the number between the closing and opening brace of the xml:
$count = preg_replace('/.*>(\d*)<.*/', '$1', $count);
[#29] charlie at blankcanvasstudios dot com [2008-08-14 11:21:28]
Optimizing aalaap at gmail dot com's php
<?php
function is_rss($feedxml) {
@$feed = simplexml_load_string($feedxml);
return ($feed->channel->item)?true:false;
}
function is_atom($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
($feed->entry):true:false;
}
?>
[#30] aalaap at gmail dot com [2008-06-30 06:58:55]
Here are two quick and dirty functions that use SimpleXML to detect if a feed xml is RSS or ATOM:
<?php
function is_rss($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
if ($feed->channel->item) {
return true;
} else {
return false;
}
}
function is_atom($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
if ($feed->entry) {
return true;
} else {
return false;
}
}
?>
The functions take in the full text feed (retrieved via cURL, for example) and return a true or a false based on the result.