note 84951 modified in function.ereg-replace by yannick

From: Date: Thu, 07 Aug 2008 13:40:37 +0000
Subject: note 84951 modified in function.ereg-replace by yannick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143269@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) <?php 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 --was-- 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 http://php.net/manual/en/function.ereg-replace.php

« previous php.notes (#143269) next »