note 42824 modified in function.preg-replace by aidan

From: Date: Sun, 22 Aug 2004 13:07:30 +0000
Subject: note 42824 modified in function.preg-replace by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75102@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: 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 (#75102) next »