note 42376 added to function.preg-replace
| From: | interiority-doot-com at rn2 dot php dot net | Date: | Thu, 13 May 2004 23:30:18 +0000 |
| Subject: | note 42376 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69587@lists.php.net to get a copy of this message | ||
I've been searching for a URL replacer that could be embedded within a function that did some
multiple preg_replace's, i.e. a small script that didn't rely on a single function alone
but still checked to see if a URL was beginning with 'http://'
or 'ftp://' etc. - or not. I've combined a few of the
things here into something hopefully useable. It only writes the domain between the href:
if ( preg_match("
(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?i", $theText) )
{
$theText = preg_replace( "(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?i",
"<a href=\"$0\" target=\"_blank\">$4</a>", $theText);
} else if ( preg_match("((\w|\.|\-|_)+)(/)?(\S+)?i", $theText) ) {
$theText = preg_replace( "((\w|\.|\-|_)+)(/)?(\S+)?i", "<a
href=\"http://$0\"
target=\"_blank\">$1</a>", $theText);
}#endif
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42376
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42376&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42376&report=yes
Search -- http://master.php.net/manage/user-notes.php