Jump to content

Extract xml data with php


cip6791

Recommended Posts

You can use SimpleXML to process XML data.

 

$sXML = new SimpleXMLElement('http://api.twitter.com/1/users/show/seobpo.xml', NULL, TRUE);
print_r($sXML);

 

You should be able to see the Twitter XML you referenced as a PHP object now and you can perform all the counting and/or transforming you want.

 

SimpleXMLElement Object ( [id] => 235570173 [name] => SEO BPO [screen_name] => seobpo [location] => New York [description] => 10 SEOs come together to launch an amazing SEO outsourcing company. [profile_image_url] => http://a2.twimg.com/profile_images/1210167979/seo-bpo_normal.jpg => http://seobpo.com [protected] => false [followers_count] => 2 [profile_background_color] => C0DEED [profile_text_color] => 333333 [profile_link_color] => 0084B4 [profile_sidebar_fill_color] => DDEEF6 [profile_sidebar_border_color] => C0DEED [friends_count] => 0 [created_at] => Sat Jan 08 14:50:50 +0000 2011 [favourites_count] => 0 [utc_offset] => SimpleXMLElement Object ( ) [time_zone] => SimpleXMLElement Object ( ) [profile_background_image_url] => http://a3.twimg.com/a/1294279085/images/themes/theme1/bg.png [profile_background_tile] => false [profile_use_background_image] => true [notifications] => SimpleXMLElement Object ( ) [geo_enabled] => false [verified] => false [following] => SimpleXMLElement Object ( ) [statuses_count] => 3 [lang] => en [contributors_enabled] => false [follow_request_sent] => SimpleXMLElement Object ( ) [listed_count] => 0 [show_all_inline_media] => false [is_translator] => false [status] => SimpleXMLElement Object ( [created_at] => Sun Jan 09 15:10:22 +0000 2011 [id] => 24120802144157696 [text] => This is our profession ! We are the best at it ! http://fb.me/EkLpCMwg [source] => Facebook [truncated] => false [favorited] => false [in_reply_to_status_id] => SimpleXMLElement Object ( ) [in_reply_to_user_id] => SimpleXMLElement Object ( ) [in_reply_to_screen_name] => SimpleXMLElement Object ( ) [retweet_count] => 0 [retweeted] => false [geo] => SimpleXMLElement Object ( ) [coordinates] => SimpleXMLElement Object ( ) [place] => SimpleXMLElement Object ( ) [contributors] => SimpleXMLElement Object ( ) ) )

 

That worked. thank you very much. But I still have no clue on how to get the tweet count. This is an array now ... right? And data can be extracted using php just like any other array? I read that xml files have categories.

Can you give me an example on how you get this: [statuses_count] => 3? I m a little confused here.

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.