I'm currently using SimplePie to parse RSS news feeds. I am successfully merging the feeds using an array, however what I need to do is return single words at random from the title, not just the whole title. Can this be done in PHP at all? I was toying around with explode()
; however didn't have any luck.
Do I need to introduce some Javascript of some sort, after the data is parsed? I know this is a little vague, I'm just trying to get a sense of what is possible (I am open to using an alternative to SimplePie, this is just what I have used so far).
Here is my code right now, which simply returns the titles as whole:
<?php
//link simplepie
require_once ('simplepie/autoloader.php');
//new simplepie class
$feed = new SimplePie();
$feed->enable_cache(true);
$feed->set_cache_duration(60);
//set up feeds
$feed->set_feed_url(array('http://mf.feeds.reuters.com/reuters/UKTopNews' , 'http://www.theguardian.com/world/rss'
));
//run simplepie
$feed->init();
//handle content type
$feed->handle_content_type();
?>
<!DOCTYPE html>
<head>
<title>News</title>
<link rel="stylesheet" type="text/css" href='style.css'>
</head>
<body>
<div class = "headlines">
<?php foreach ($feed->get_items(0, 10) as $item): ?>
<?php $item->get_title(); ?>
<h4><?php echo $item->get_title(); ?></h4>
<?php endforeach; ?>
</div>
</body>
</html>
Thanks!