note 81169 added to function.preg-replace
| From: | ShashankTripathi at osu1 dot php dot net | Date: | Sat, 16 Feb 2008 15:33:03 +0000 |
| Subject: | note 81169 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136205@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 202.79.178.91
Probable Submitter: 218.186.14.74 (proxied: 218.212.6.27)
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/81169
Del: integrated -- https://master.php.net/note/delete/81169/integrated
Del: useless -- https://master.php.net/note/delete/81169/useless
Del: bad code -- https://master.php.net/note/delete/81169/bad+code
Del: spam -- https://master.php.net/note/delete/81169/spam
Del: non-english -- https://master.php.net/note/delete/81169/non-english
Del: in docs -- https://master.php.net/note/delete/81169/in+docs
Del: other reasons-- https://master.php.net/note/delete/81169
Reject -- https://master.php.net/note/reject/81169
Search -- https://master.php.net/manage/user-notes.php