Add Twitter feeds to your web site using Simple XML
Add Twitter feeds to your web site using Simple XML: see example
//Simply add this section of the code somewhere on top of the page -->//
<?php
function twitter_status($twitter_id, $hyperlinks = true) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_TIMEOUT, 5);
$response = curl_exec($c);
$responseInfo = curl_getinfo($c);
curl_close($c);
if (intval($responseInfo['http_code']) == 200) {
if (class_exists('SimpleXMLElement')) {
$xml = new SimpleXMLElement($response);
return $xml;
} else {
return $response;
}
} else {
return false;
}
}
?>
// --> Add this section of the code where you want to display the TWITTER feed. You just need to make some adjustments and modification to suite your needs. //
<?php
if ( $twitter_xml = twitter_status('TWITTER_ID') ) {
foreach ($twitter_xml->status as $key => $status) {
?>
- <?php echo $status->text; ?><br/><br/>
<?php
++$i1;
if ($i1 == 5) break;
}
?>
<li><a href="http://twitter.com/statuses/user_timeline/TWITTER_ID.rss">more...</a></li>
<?php
} else {
echo 'Sorry, Twitter seems to be unavailable at the moment...again...';
}
?>

