简体   繁体   中英

How parse RSS feed

I'm trying to parse an RSS feed in PHP for the first time. It seems to go fine until I actually try to display anything! This example is me trying to pull out four random organization names from the feed (I actually want to display more, but am keeping it simple here...)

$xml = file_get_contents('https://rss.myinterfase.com/rss/oxford_RSS_Jobs_xml.xml');
foreach($xml->Row as $job) {
$item[] = array(
                 'OrganizationName'  => (string)$job->OrganizationName,
                 'job_JobTitle'      => (string)$job->job_JobTitle,
                 'job_expiredate'    =>  strtotime($job->job_expiredate),
                 'ExternalLink'      => $job->ExternalLink
                 );
}
$rand_job = array_rand($item, 4);
$i=0;
echo '<ul>';
while($i<=3) { 
echo '<li>';
echo $item[$i]['OrganizationName'];
echo '</li>';
$i++;
}
echo '</ul>'

What do I need to do differently? Thanks!

You have to use simplexml_load_file($url); or similar.

$url = 'https://rss.myinterfase.com/rss/oxford_RSS_Jobs_xml.xml';

$xml = simplexml_load_file($url);
foreach($xml->row as $job) { // be sure about $xml->row. If it's full path to this elements
//..... your code
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM