note 30406 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 22:02:15 +0000 |
| Subject: | note 30406 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55687@lists.php.net to get a copy of this message | ||
Note Submitter: alper@sabanciuniv.edu
----
Fixed code for replace an url within a text with a link.
This code work for all http and www included text. Some code above doesn't work addresses
include numeric data.
And this work for address included numeric too.
I hope you like it :)
function parCalla($text)
{
$text = preg_replace("((http://|ftp://)?([a-zA-Z1-9\-_\.]+
\.[a-zA-Z1-9\-_]+\.[a-z]{2,3}(/[a-zA-Z1-9\-/\._\?=&]+)?))",
"<a href=\"\\1\\2\" target=\"_blank\">\\0</a>", $text);
return preg_replace("((href=\")([a-zA-Z1-9\-_\.]+
\.[a-zA-Z1-9\-_]+\.[a-z]{2,3}(/[a-z\-/\._\?=&]+)?))",
"href=\"http://\\2", $text);
}