note 27052 deleted from function.ereg-replace by kennyt
| From: | kennyt@php.net | Date: | Wed, 26 Jan 2005 03:55:03 +0000 |
| Subject: | note 27052 deleted from function.ereg-replace by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83986@lists.php.net to get a copy of this message | ||
Note Submitter: johnl at noimagestyspam dot gr
----
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.