note 30406 added to function.preg-replace
| From: | alper at sabanciuniv dot edu | Date: | Mon, 17 Mar 2003 12:20:01 +0000 |
| Subject: | note 30406 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45412@lists.php.net to get a copy of this message | ||
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);
}
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+30406
http://master.php.net/manage/user-notes.php?action=delete+30406
http://master.php.net/manage/user-notes.php?action=reject+30406