cip6791 Posted January 11, 2011 Share Posted January 11, 2011 I can t seem to get this. I need to extract some data from the following xml file. http://api.twitter.com/1/users/show/seobpo.xml I just want to get seobpo's tweet count. The data will be used in a wordpress blog. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/224079-extract-xml-data-with-php/ Share on other sites More sharing options...
beegro Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224079-extract-xml-data-with-php/#findComment-1157888 Share on other sites More sharing options...
cip6791 Posted January 11, 2011 Author Share Posted January 11, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224079-extract-xml-data-with-php/#findComment-1157895 Share on other sites More sharing options...
beegro Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224079-extract-xml-data-with-php/#findComment-1157900 Share on other sites More sharing options...
cip6791 Posted January 11, 2011 Author Share Posted January 11, 2011 Beautiful ... thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/224079-extract-xml-data-with-php/#findComment-1157903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.