Jump to content

Selecting Data From XML Tags in PHP


Prodjex

Recommended Posts

I need to grab the data from the “enclosure” tag from the following feed:

https://queryfeed.net/twitter?q=%40CabosNews&title-type=user-name-both&geocode=

In the example, you can modify the “enclosure” field to any of the fields you need help grabbing.  This is using the simplexml_load_string command.

$url = 'https://queryfeed.net/twitter?q=%40CabosNews&title-type=user-name-both&geocode=';
$xml = file_get_contents($url);
$obj = simplexml_load_string($xml);

foreach ($obj->channel->item as $item)
{
    echo PHP_EOL . (string)$item->enclosure['url'];
}

This will give you an output on your page of:

https://pbs.twimg.com/media/CLfaPSgWwAExQjM.jpg
https://pbs.twimg.com/media/CLfaO8oWUAAhJ3N.jpg
https://pbs.twimg.com/media/CLfaOiWWwAAWkGI.jpg
https://pbs.twimg.com/media/CLfaOIkWoAA7Ur3.jpg
https://pbs.twimg.com/media/CLfaNu7WUAAWV-4.jpg
https://pbs.twimg.com/media/CLfaNWVWUAItN_4.jpg
https://pbs.twimg.com/media/CLfaNFlWgAA9dA3.jpg
https://pbs.twimg.com/media/CLfaMqjWoAAVNUy.jpg
https://pbs.twimg.com/media/CLfaML6WcAACoj-.jpg
https://pbs.twimg.com/media/CLfMg89W8AEr7lj.jpg

You can see the demo output here.

The post Selecting Data From XML Tags in PHP appeared first on Kansas City Web Consulting | Kansas City Web Development.

View the full article

Link to comment
Share on other sites

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.   Paste as plain text instead

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