note 26709 deleted from function.ereg-replace by tularis

From: Date: Sun, 29 Aug 2004 12:18:43 +0000
Subject: note 26709 deleted from function.ereg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75566@lists.php.net to get a copy of this message
Note Submitter: chalx#mailru.com ---- Here is another one "Replace URLs with links" example. It is certainly wrong for some small subset of cases, but it's much more usable than current manual example (causing bug even used on this notes - see url in post #3 from 01-02-02). For some read/write/performance reasons the expression was split into several variables. It's sure possible to concatenate all in one string, but it gives nothing good. $vdom = "[:alnum:]"; // Valid domain chars $vurl = $vdom."_~-"; // Valid subdomain and path chars $vura = "À-ßà-ÿ!#$%&*+,;=@.".$vurl; // 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) $str = ereg_replace("$protocol$server(/$path($name)?)?($params)?", "<a href=\"\\0\">\\0</a>", $str); // URL into links

« previous php.notes (#75566) next »