note 47734 added to function.preg-replace
| From: | adamatreleoddotcom at osu1 dot php dot net | Date: | Fri, 26 Nov 2004 23:50:25 +0000 |
| Subject: | note 47734 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81085@lists.php.net to get a copy of this message | ||
In addition to pauls note. If you have a string as follows
"today I went to http://www.google.com it was great"
anything after the url is automatically parsed into the clickable link.
Quick fix as follows
<?
$text = "Hello World. Today I visited http://www.google.com/ for the first time";
$text = preg_replace("/(http:\/\/(.*)\/)[\S]*/", "<a href=\\1>\\1</a>
", $text);
echo $text;
?>
Simply add \/ After the (.*)
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47734
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47734&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47734&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47734&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47734&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47734&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47734&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47734&report=yes
Search -- http://master.php.net/manage/user-notes.php