Friday, June 12, 2009

Formatting messages to look like twitter messages in php

Basically suppose you have twitter message in plain text form and you may want to display it on a webpage with all @names pointing to twitter profiles and links to apporpriate pages

just use the following php function

function formatTweet($tweet)
//select hyperlinks
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"\\0", $tweet);
$text = ereg_replace("@([a-zA-Z0-9_]+)","@\\1",$text);
return $text;