Written: July 24, 2009

More Twitter Feed Tweaks

I blogged earlier about how I found this cool PHP class to read my tweets and post them on a marketing blog page. The tweets were just unformatted and didn’t have any links in them so I set about to upgrade the formatting to add links to:

Here’s what I did in PHP using the preg_replace function:
foreach($data as $tweet) {
// Replace # with link to search.twitter.com, replace @ with link to twitter account
$link = preg_replace(“_http://[a-zA-Z0-9\./]+_”,”<a href=’$0′>$0</a>”,$tweet->text);
$replace_pound = preg_replace(“/#[a-zA-Z0-9]+/”,”<a href=’http://search.twitter.com/search?q=$0′>$0</a>”,$link);
$html_pound = preg_replace(“/q=#/”,”q=%23″,$replace_pound);
$replace_at = preg_replace(“/@[a-zA-Z0-9_]+/”,”<a href=’http://twitter.com/$0′>$0</a>”,$html_pound);
$html_at = preg_replace(“_twitter.com/@_”,”twitter.com/”,$replace_at);
print “<li>$html_at</li>
“;
}

Here’s what the linked tweet feed now looks like:

Tags:

2 responses to “More Twitter Feed Tweaks”

  1. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to create my own blog and would like to find out where u got this from. appreciate it

  2. Daniel Payne says:

    I created this custom theme from scratch. My business is to develop custom themes, plugins and features for web sites, both WordPress and custom.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Blog Tags

Recent Posts

Blog Directory & Business Pages at OnToplist.com