note 42824 modified in function.preg-replace by jacques

From: Date: Thu, 26 Aug 2004 07:43:23 +0000
Subject: note 42824 modified in function.preg-replace by jacques
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75296@lists.php.net to get a copy of this message
Yet another simple URL link maker. This one ignores any period at the end of the URL which is usually a good thing: <?php function MakeUrl($strUrl) { $strUrl = preg_replace("/(http(s)?:\/\/[^\s\\n]*)\\b(\/)?/i","<a href=\"\\0\">\\0</a>",$strUrl); return $strUrl; } MakeUrl("Blah, blah, http://php.net/."); // result: "Blah, blah, <a href="http://php.net/">http://php.net/</a>." ?> --was-- Yet another simple URL link maker. This one ignores any period at the end of the URL which is usually a good thing: <?php function MakeUrl($strUrl) { $strUrl = preg_replace("/(http(s)?:\\/\\/[^\\s\\n]*)\\b(\\/)?/i","<a href=\\"\\\\0\\">\\\\0</a>",$strUrl); return $strUrl; } MakeUrl("Blah, blah, http://php.net/."); // result: "Blah, blah, <a href="http://php.net/">http://php.net/</a>." ?> http://php.net/manual/en/function.preg-replace.php

« previous php.notes (#75296) next »