note 82970 added to function.ereg-replace
| From: | http://www dot bbgames dot co dot nr at osu1 dot php dot net | Date: | Sun, 04 May 2008 14:57:01 +0000 |
| Subject: | note 82970 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139048@lists.php.net to get a copy of this message | ||
In response to a post above, his coding was a bit wrong. The correct coding should be :
<?php
function hyperlink($text)
{
// match protocol://address/path/
$text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "<a
href=\"\\0\">\\0</a>", $text);
// match www.something
$text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
// return $text
return $text;
}
?>
You can use this function like this:
<?php
$line = "Check the links: www.yahoo.com http://www.php.net";
hyperlink($line);
// Now, all text that looks like a link becomes a link
?>
----
Server IP: 208.69.120.35
Probable Submitter: 96.228.159.168
----
Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php
Edit -- https://master.php.net/note/edit/82970
Del: integrated -- https://master.php.net/note/delete/82970/integrated
Del: useless -- https://master.php.net/note/delete/82970/useless
Del: bad code -- https://master.php.net/note/delete/82970/bad+code
Del: spam -- https://master.php.net/note/delete/82970/spam
Del: non-english -- https://master.php.net/note/delete/82970/non-english
Del: in docs -- https://master.php.net/note/delete/82970/in+docs
Del: other reasons-- https://master.php.net/note/delete/82970
Reject -- https://master.php.net/note/reject/82970
Search -- https://master.php.net/manage/user-notes.php