Nicolas Quirin wrote:
Hi,
i'm french, i'm using regular expressions in php in order to rewrite hyperlink tags in a specific way before apache output is beeing sent to client.
Purpose is to replace href attribute of any A html tag by a javascript function calling an ajax loader.
Currently I have wrote that:
$pattern = '/<a href="(http:\/\/dev.netdoor.fr|(\.))\/index.php\?page=(.*?)">(.*?)<\\/a>/i';
$replacement = '<a href="javascript:void(0);" OnClick="javascript:yui_fastLoader(\'./systeme/chargeur.php?page=$4\');">$5</a>';
$html_mark = preg_replace($pattern, $replacement, $html_mark);
it works, but it's too permissive, it replaces too much links (some links with some get parameters must stay unchanged)
I don't really understand my pattern...it's a little strange for me...lol
I wouldn't like to rewrite links that contains any of the following words in get parameters (query string):
noLoader
noLeftCol
skipallbutpage
skipservice
i would like to rewrite only link that begin with 'http://dev.netdoor.fr' or '.'
examples:
<a href="http://dev.netdoor.fr/index.php?page=./comptes/index.php&noLoader&noLeftCol&idx=6&bdx=423&skipservice">test</a>
=>must be not rewritted!
<a class="myclass" href="./index.php?page=./comptes/mediatheque/index.php&filter=mov;flv;mpeg&idx=7">name</a>
=>must be rewritted like this :
<a class="myclass" href="javascript:void(0);" OnClick="javascript:yui_fastLoader(\'./systeme/chargeur.php?page=./comptes/mediatheque/index.php&filter=mov;flv;mpeg&idx=7\');">name</a>
Please help me...:0)
best regards
nicolas
The key here is (?!) - the negative assertion, it should look something
like this:
$p = '#<a
href="(?:\.|http://dev.netdoor.fr)/index\.php\?page=(?![^"]*(?:noLoader|noLeftCol|skipallbutpage|skipservice))([^"]*)">(.*?)</a>#is';
$r = '<a href="javascript:void(0);"
OnClick="javascript:yui_fastLoader(\'./systeme/chargeur.php?page=$1\');">$2</a>';
Arpad
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php