note 27052 added to function.ereg-replace

From: Date: Thu, 21 Nov 2002 12:37:01 +0000
Subject: note 27052 added to function.ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-39803@lists.php.net to get a copy of this message
chalx provides a very good piece of code but it cannot detect URLs like www.imagesty.gr (i.e. those without a protocol) if you are interested in finding and replacing these too here is his code modified to do so : $vdom = "[:alnum:]"; // Valid domain chars $vurl = $vdom."_~-"; // Valid subdomain and path chars $vura = $vurl."A-?a-y!#$%&*+,;=@."; // Valid additional parameters (after '?') chars; // insert other local characters if needed $protocol = "[[:alpha:]]{3,10}://"; // Protocol exp $server = "([$vurl]+[.])+[$vdom]+"; // Server name exp $path = "(([$vurl]+([.][$vurl]+)*/)|([.]{1,2}/))*"; // Document path exp (/.../) $name = "[$vurl]+([.][$vurl]+)*"; // Document name exp $params = "[?][$vura]*"; // Additional parameters (for GET) $output1 = ereg_replace("($protocol)?($server(/$path($name)?)?)", "<a href=\"http://\\2\">\\0</a>", $input); // URL into links Have in mind that parameters didn't work for me (i got an "invalid range end" error so i removed it and that all links are created with http:// in front which might be bad for some people. If anyone has any idea how to improve please post. Hope this helps somebody. -- http://www.php.net/manual/en/function.ereg-replace.php http://master.php.net/manage/user-notes.php?action=edit+27052 http://master.php.net/manage/user-notes.php?action=delete+27052 http://master.php.net/manage/user-notes.php?action=reject+27052

« previous php.notes (#39803) next »