function markup_urls ($text
{
// split the text into words
$words = preg_split'/([snr]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$text = ""
// iterate through the words
foreach$words as $word) {
// chopword = the portion of the word that will be replaced
$chopword = $word
$chopword = preg_replace'/^[^A-Za-z0-9]*/', '', $chopword);
if ($chopword <> '') {
// linkword = the text that will replace chopword in the word
$linkword''
// does it start with http://abc. ?
if (preg_match'/^(http://)[a-zA-Z0-9_]{2,}.*/', $chopword)) {
$chopword = preg_replace'/[^A-Za-z0-9/]*$/', '', $chopword);
$linkword = '<a href="'$chopword'" target="blank">'$chopword'</a>'
// does it equal abc.def.ghi ?
} else if (preg_match'/^[a-zA-Z]{2,}.([a-zA-Z0-9_]+.)+[a-zA-Z]{2,}(/.*)?/', $chopword)) {
$chopword = preg_replace'/[^A-Za-z0-9/]*$/', '', $chopword);
$linkword = '<a href="http://'$chopword'" target="blank">'$chopword'</a>'
// does it start with [email protected] ?
} else if (preg_match'/^[a-zA-Z0-9_.]+@([a-zA-Z0-9_]{2,}.)+[a-zA-Z]{2,}.*/', $chopword)) {
$chopword = preg_replace'/[^A-Za-z0-9]*$/', '', $chopword);
$linkword = '<a href="mailto:'$chopword'">'$chopword'</a>'
}
// replace chopword with linkword in word (if linkword was set)
if ($linkword <> '') {
$word = str_replace$chopword, $linkword, $word);
}
}
// append the word
$text = $text$word
}
return $text
}