Coding For Online Success

Including Twitter updates in your site


A client of mine wanted to include his Twitter feeds into his site. This is quite easy using the cURL library to access the Twitter RSS or XML feed. This might be a nice way to dynamically include additional content into your site. There are Twitter widgets that embed content into your site, but they use JavaScript to do this. Personally, I want this content to be read by bots, so PHP/HTML integration is a good option.

Basically, using cURL, you can bring in the RSS feed or XML feed. The RSS feed only includes date and status, and the XML feed will give you additional information including profile information (website, bio, etc).

I wrote a simple custom function which I’ve used in other examples here on the site called send_request(). This calls the request for the RSS file.

span class=”co1″>// set to zero for no timeout

This function can be on the same script or in a include file. Next we need to assemble the querystring to send to our function. The function will return the XML which we parse with simplexml_load_string(). I should mention that this script will work with PHP compiled with simplexml and have cURL extension. If you’re using PHP4, you’ll need to use a different method to parse XML using DOM.

$username       = ‘hanjicode’;
$rssUrl         = ‘’.$username.‘.rss’‘: ‘,‘ – ‘


It looks through the RSS result and displays the contents to the browser. Let me know if you have any suggestions with this script or if you have any problems. I’ll be more than happy to help.

Leave a Reply

Required fields are marked *.

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.