note 42562 added to function.preg-replace

From: Date: Fri, 21 May 2004 12:00:31 +0000
Subject: note 42562 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-69904@lists.php.net to get a copy of this message
This is my 1st regex and I like this one. I wrote it for my forum to filter all kind of http(s) urls. [php] echo filter("www.website.com") . "<br />"; // result: http://www.website.com echo filter("https://website.com:8000") . "<br />"; // result: https://website.com:8000 echo filter("forum.website.com/245/54") . "<br />"; // result: http://forum.websute.com/245/54 function filter( $message ) { return( preg_replace( "/((http)(s)?:\/\/)?([a-z]{3,}\.)?([\S]{3,}) (\.[a-z]{2,4})([\S]{1,})?/i", "<a href=\"http\\\\3://\\\\4\\\\5\\\\6\\\\7\">\\\\0</a>", $message ) ); } [/php] Hope someone can use it :) When finding a space in an url, the url will terminate. Space has to be %20 --> http://www.website.com/my%20directory ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42562 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42562&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42562&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69904) next »