note 55028 added to reference.pcre.pattern.syntax
| From: | davout_69 at yahoo dot com | Date: | Fri, 22 Jul 2005 19:36:53 +0000 |
| Subject: | note 55028 added to reference.pcre.pattern.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92317@lists.php.net to get a copy of this message | ||
Found a great expression that replaces a text url - http:/.... with <a
href ="http://www...">
Although it works, I still don't understand how. If someone could explain this it would great
to learn what amounts to me as a foreign language :-)
Here is the expression:
'%"(.+)"[\s]+((http|https|ftp|file)://[^\s]+?)(.*)%sU'
$pcre = '%"(.+)"[\s]+((http|https|ftp|file)://[^\s]+?)(.*)%sU';
if ( preg_match( $pcre, $lines ) ){
$lines = preg_replace( $pcre, '<a href="$2"
target="_top">$1</a>$4', $lines );
} else {
$pcre = '%\b((http|https|ftp|file)://[^\s]+?)(.*)%U';
$lines = preg_replace( $pcre, '<a href="$1"
target="_top">$1</a>$3', $lines );
}
----
Manual Page -- http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55028
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55028&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55028&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55028&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55028&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55028&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55028&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55028&report=yes
Search -- http://master.php.net/manage/user-notes.php