note 29803 added to function.preg-replace
| From: | php at rack1 dot php dot net | Date: | Tue, 25 Feb 2003 16:22:08 +0000 |
| Subject: | note 29803 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44508@lists.php.net to get a copy of this message | ||
Closer to the Holy Grail...
Same function as before (see above a couple spots), but now using forward and back references. Will
spot and trim URLs which end in more than one non-word chracter.
So: www.someurl.com!!?!?!
Becomes:
<a href="http://www.someurl.com">www.someurl.com</a>!!?!?!
function addLinks($string) {
$string = preg_replace(
"/(?<!quot;|[=\"]|:\/\/)\b((\w+:\/\/|www\.).+?)".
"(?=\W*([<>\s]|$))/i", "<a
href=\"$1\">$1</a>", $string);
return preg_replace("/href=\"www/i", "href=\"http://www", $string);}
Enjoy, I hope! :)
Grey
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+29803
http://master.php.net/manage/user-notes.php?action=delete+29803
http://master.php.net/manage/user-notes.php?action=reject+29803