PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

SitePoint PHP Blog: How to Create Your Own Twitter Widget in PHP, Part 2

Note: This article was originally published at PHPDeveloper on 7 January 2011.
PHPDeveloper

On the SitePoint PHP blog today Craig Buckler is back with the second part of their series on creating a Twitter widget for your site. You can find more about the first part of the series here.

In Part 1 of this series, we examined the Twitter API, creating a PHP TwitterStatus class, and imported the latest tweets in JSON format. Today, we'll populate the data into HTML templates - download the full source code here.

The templates are strings of HTML with tags for where the content belongs - in this case things like "{TWEETS}" and "{profile_image_url}". Regular expressions are used to parse the templates and a str_replace used to make the substitution. The final product is included showing a few example tweets with some parsed links inside each.