What up friends, I'm using this little function to parse hyperlinks in plain text and convert them into links. It goes like so
...This works great however it doesn't parse URL's that have query strings at the end such as . If somebody could modify it to make it work with those I would be extremely grateful. Also, if it's not to difficult, it would be extremely beneficial to have it parse blip urls in the formThanks a bunch guys!
Code:
private function hyperlink($text) {
// match protocol://address/path/
$text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\">\\0</a>", $text);
// match www.something
$text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
// match @replys
$text = preg_replace("/[@]+[A-Za-z0-9-_]+/", "<a href=\"http://twitter.com/\\0\">\\0</a>", $text);
// match #hashtags
$text = preg_replace("/[#]+[A-Za-z0-9-_]+/", "<a href=\"http://search.twitter.com/search?q=\\0\">\\0</a>", $text);
// fix Twitter URLs
$text= str_replace("<a href=\"http://twitter.com/@","<a target=\"_blank\" href=\"http://twitter.com/",$text);
$text= str_replace("<a href=\"http://search.twitter.com/search?q=#","<a target=\"_blank\" class=\"hashtag\" href=\"http://search.twitter.com/search?q=%23",$text);
// return $text
return $text;
}
Comment