I’m making a small RSS reader and I want it to parse a website and make a list of the feed. But the <ul> and <li> tags aren’t being rendered. Any suggestions?
<?php
header("Content-Type: text/plain; charset=utf-8");
function jobs() {
$output = array();
$feed_url = 'http://www.jobs.ge/rss/jobs/';
$feed = simplexml_load_file($feed_url);
for($j=0; $j<10; $j++){
$title = $feed ->channel->item[$j]->title;
$link = $feed ->channel->item[$j]->link;
$desc= $feed ->channel->item[$j]->description;
$date = $feed ->channel->item[$j]->pubDate;
$output[] = array (
'title' =>$title,
'link' =>$link,
'description'=> $desc,
'date'=> $date,
);
}
return $output;
}
$feed = jobs();
?>
<ul>
<?php
foreach ($feed as $item) {
echo '<li>', $item['title'],'</li>';
}
?>
</ul>
You set the content-type to
text/plainso the browser does what it should and renders it as plain text. Set the content-type totext/htmland it should render even though it’s not completely valid HTML.