TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   serialize XML Category (http://www.talkphp.com/advanced-php-programming/4950-serialize-xml-category.html)

russellharrower 09-15-2009 04:31 PM

serialize XML Category
 
I have been working on this for around 2 days now, Having the same issue it seems that I can serialize the categories.

They return the following
Code:

Array ( [0] => SimpleXMLElement Object ( ) ) a:1:{i:0;O:16:"SimpleXMLElement":0:{}}
Does any one now how to fix this issue?

PHP Code:

<?php
  $feed 
file_get_contents("http://www.techau.tv/blog/?feed=rss2");
  
$xml = new SimpleXmlElement($feed);
  foreach (
$xml->channel->item as $entry)
  {
    echo 
$entry->title.'<br/>';
    echo 
$entry->description.'<br/><br/>';
    
    
$keywordsArray = array();
    foreach (
$entry->category as $a => $b)
    {
      
$keywordsArray[] = $b;
    }
    
print_r($keywordsArray);
    
//serialize keyword array ready for posting in link
    
$keywords str_replace(
      array(
'O:16:"SimpleXMLElement":0:{}''O:16:"SimpleXMLElement":'),
      array(
's:0:"";''O:8:"stdClass":'),
      
serialize($keywordsArray)
      );    
    print 
$keywords;
    print 
"<br/><br/>";
  }
?>


adamdecaf 09-15-2009 08:50 PM

PHP Code:


$file 
simplexml_load_file('http://www.techau.tv/blog/?feed=rss2');

print_r($file); 

Done.

ETbyrne 09-16-2009 01:57 AM

For simple XML adamdecaf's solution should work just fine. However, if you plan on parsing loosely-typed XML (like HTML) and you don't want to mangle the data then you will have to use the DOMDocument class to manually parse the XML.

I wrote a class for Dingo that safely serializes and de-serializes loosely-typed XML by using the DOMDocument class, but you won't be able to get your hands on that until Oct 1.


All times are GMT. The time now is 10:33 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0