forked from bcit-ci/CodeIgniter
-
Notifications
You must be signed in to change notification settings - Fork 26
Twitter Tweet Parser
World Wide Web Server edited this page Jul 4, 2012
·
5 revisions
[b]Introduction[/b]
Twitter Apps are all the rage these days. When displaying a tweet, there is actually a lot of information that comes back from twitter's servers, and It's always plain text. This helper simply parses the tweet, and converts the plain-text into marked up embedable code. [code]
if (!function_exists('parse_tweet')) { function parse_tweet($tweet) { $search = array('|(http://[^ ]+)|', '/(^|[^a-z0-9_])@([a-z0-9_]+)/i', '/(^|[^a-z0-9_])#([a-z0-9_]+)/i'); $replace = array('$1', '$1@$2', '$1#$2'); $tweet = preg_replace($search, $replace, $tweet);
return $tweet;
}
}
[/code]
[b]Usage[/b]
Simply pass this helper a tweet, and it returns the text with hyperlinks embedded.
[code] $parsed_tweet = parse_tweet($tweet_text); [/code]