candybrie Posted July 12, 2012 Share Posted July 12, 2012 Ok so this is the xml I'm trying to read basically goes: <tumblr> <posts> <post url="http://stuff"> other stuff </post> <post url="http://stuff"> other stuff </post> <post url="http://stuff"> other stuff </post> </posts> </tumblr> If it helps to actually see it: http://candybrie.tumblr.com/api/read?type=post&start=0&num=4&type=text My problem is getting the url's from each post. The relevant php looks like this: foreach ($xml->posts->post AS $post) { $title = $post->{'regular-title'}; $post = $post->{'regular-body'}; $link = $post->attributes()->url; $small_post = substr($post,0,320); echo '<h1>'.$title.'</h1>'; echo '<p>'.$small_post; echo "?"; echo '<a target=frame2 href="'.$link.'">Read More</a></p>'; } The problem is with getting the url attribute, it gives me nothing. If I do this $link = $xml->posts->post->attributes()->url; I can get the first post's. This is the first thing I've actually done in php so sorry if there is a really obvious answer or flaw. Link to comment https://forums.phpfreaks.com/topic/265553-simplexml-attribute-wont-be-read-in-foreach-loop/ Share on other sites More sharing options...
requinix Posted July 12, 2012 Share Posted July 12, 2012 $post = $post->{'regular-body'}; You overwrote $post with something else. Link to comment https://forums.phpfreaks.com/topic/265553-simplexml-attribute-wont-be-read-in-foreach-loop/#findComment-1361003 Share on other sites More sharing options...
candybrie Posted July 12, 2012 Author Share Posted July 12, 2012 Oh. I feel rather silly. Thank you. Link to comment https://forums.phpfreaks.com/topic/265553-simplexml-attribute-wont-be-read-in-foreach-loop/#findComment-1361004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.