note 81169 deleted from function.preg-replace by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 22:58:46 +0000 |
| Subject: | note 81169 deleted from function.preg-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137393@lists.php.net to get a copy of this message | ||
Note Submitter: Shashank Tripathi
----
The code by Swedish Boy and others to replace hyperlinks is not very efficient. You can manage this
in just one preg command instead of treating the text to three of them!
Here's a more efficient version of it:
--------------
function hyperlink($url)
{
if (preg_match(
'/^(rtsp|mms|mmst|http|https|ftp|mailto|call|news):\/LINEBREAK
\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/i'
,$url
)) {
return '<a href="' . $url . '" target="_blank">' .
$url . '</a>';
}
else { return $url; }
}
--------------
This commenting system on the php.net site does not allow lines longer than a certain character
limit, so my code has the word "LINEBREAK" in it. Delete that word and make sure you
delete nothing else. The two lines separated by LINEBREAK will become one line in your code.
Hope this helps.