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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

The variable $sXML is now an object with all the XML tags being attributes.  So, to retrieve the tag [statuses_count] from the XML simply access it in PHP's object form

 

$sXML->statuses_count

 

That will return the value of [statuses_count], this case being 3.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.