Jump to content

xml


ohdang888

Recommended Posts

so within an xml file, i have this:

 

<description><![CDATA[this is an excerpt of the 2nd post]]></description>

<content:encoded><![CDATA[<p>This is the body of the 2nd post on this blog. It is meant to test Crawler attributes, etc</p>

]]></content:encoded>

 

$data['description'] works fine, but the content:encoded doesn't exist within the array?

 

Any ideas?

Thanks

 

i'm using simple xml and this function to turn it into an array:

function simplexml_to_array($xml) {
   $ar = array();
   foreach($xml->children() as $k => $v) {
       // recurse the child
       $child = simplexml_to_array($v);
       // if it's not an array, then it was empty, thus a value/string
       if( count($child) == 0 ) {
           $child = (string)$v;
       }

       // add the childs attributes as if they where children
       foreach( $v->attributes() as $ak => $av ) {
           // if the child is not an array, transform it into one
           if( !is_array( $child ) ) {
               $child = array( "value" => $child );
           }
           $child[$ak] = (string)$av;
       }

       // if the $k is already in our children list, we need to transform
       // it into an array, else we add it as a value
       if (!in_array($k,array_keys($ar))) {
           $ar[$k] = $child;
       } elseif (@in_array(0,@array_keys($ar[$k]))) {
           $ar[$k][] = $child;
       } else {
           $ar[$k] = array($ar[$k]);
           $ar[$k][] = $child;
       }

   }
   return $ar;
}

Link to comment
https://forums.phpfreaks.com/topic/202591-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.