improve turning urls into links routine
| From: | Peter J. Schoenster | Date: | Mon, 28 Jan 2002 22:17:04 +0000 |
| Subject: | improve turning urls into links routine | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82471@lists.php.net to get a copy of this message | ||
Hi,
I did a quick search for something like this below but did not find it.
Would you please criticize it. Thanks.
function &MakeUrls(&$data) {
$words = explode(" ", $data);
$new_data = "";
while (list ($key,$row) = each ($words) ) {
if (preg_match ("/^http:\/\//", $row)) {
// should just be the url here
$new_data .= "<a href=\"$row\">$row</a> ";
continue;
}
if (preg_match ("/http/", $row)) { // catch on the line
break which I did not explode on
$row = preg_replace ("/(http[^\s]+)/","<a
href=\"\\1\">\\1</a>", $row);
}
$new_data .= "$row ";
}
return $new_data;
} # End Get
Peter
---------------------------
"Reality is that which, when you stop believing in it, doesn't go
away".
-- Philip K. Dick