Re: RegExp adaptation hell...

From: Date: Fri, 18 Apr 2003 04:48:58 +0000
Subject: Re: RegExp adaptation hell...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144461@lists.php.net to get a copy of this message
I'm sure there is some sweet way to do it, but why don't you just do it in two passes. The first one just put www.mydomain.org in the regex and the second one replace all {h1} links and include the image. This will be slow, but if you don't get any better ideas... <speedfreak@chello.be> wrote in message news:3E9F6618.8A9C3F1@chello.be... > For a CMS I need to implement a feature which adds a > 'link-points-offsite' image to all external hyperlinks (don't ask). I > already use the regular expression in the example below to turn EVERY > pseudo_URL {hl:XXX}...{/hl} into valid HTML hyperlinks (works fine, thx > to Marek Kilimajer). > > Example: > $foo = "This is an {hl:http://www.test.org/1}external > link{/hl}. And > this is an > {hl:http://www.mydomain.org/2}internal one{/hl}."; > $foo = preg_replace('|{hl:([^}]+)}([^{]+){/hl}|', > '<a href="$1">$2'.$offsite_img.'</a>',$foo); > > Result: > 'This is an <a > href="http://www.test.org/1">external > link.$offsite_img</a>. And this is an <a > href="http://www.mydomain.org/2">internal > one.$offsite_img</a>.' > > My question: > Since I cannot get my head around it, is anybody able to adapt the > regexp so that it ONLY replaces external pseudo_URLs (don't contain > 'mydomain')? > > Please cc me (digest subscriber), > speedfreak >

« previous php.general (#144461) next »