- file_get_contents: documentation ( source)
- str_replace: documentation ( source)
- explode: documentation ( source)
<?php
$username = "w3resource";
$feed = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=2";
// $prefix = '<h3>corePHP</h3>';
// $suffix = '<p><a href="http://twitter.com/'.$username.'">Follow us on Twitter</a></p>';
function parse_feed($feed) {
$stepOne = explode('<content type="html">', $feed);
$stepTwo = explode('</content>', $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
return $tweet;
}
$latest_tweet = file_get_contents($feed);
// echo stripslashes($prefix) . parse_feed($latest_tweet) . stripslashes($suffix);
echo parse_feed($latest_tweet);