note 84951 added to function.ereg-replace
| From: | computer_guru at osu1 dot php dot net | Date: | Wed, 06 Aug 2008 23:39:36 +0000 |
| Subject: | note 84951 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143259@lists.php.net to get a copy of this message | ||
Here is the code I use to make links clickable. The code only works on xxxx:// (i.e. ftp://, http://, etc...). It does not work on www. because that is how I want it.
The reason my code has an if condition is that it ignores html links and only modifies non-html
urls. (see below)
<?
function make_clickable($text)
{
if (ereg("[\"|'][[:alpha:]]+://",$text) == false)
{
$text = ereg_replace('([[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/])', '<a
target=\"_new\" href="\\1">\\1</a>', $text);
}
return($text);
}
?>
My function ignores code like this:
<a href="http://php.net"> php.net </a>
But it would make this one click able:
http://php.net
----
Server IP: 209.41.74.194
Probable Submitter: 68.118.72.19
----
Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php
Edit -- https://master.php.net/note/edit/84951
Del: integrated -- https://master.php.net/note/delete/84951/integrated
Del: useless -- https://master.php.net/note/delete/84951/useless
Del: bad code -- https://master.php.net/note/delete/84951/bad+code
Del: spam -- https://master.php.net/note/delete/84951/spam
Del: non-english -- https://master.php.net/note/delete/84951/non-english
Del: in docs -- https://master.php.net/note/delete/84951/in+docs
Del: other reasons-- https://master.php.net/note/delete/84951
Reject -- https://master.php.net/note/reject/84951
Search -- https://master.php.net/manage/user-notes.php