Re: RegExp adaptation hell...

From: Date: Fri, 18 Apr 2003 07:44:31 +0000
Subject: Re: RegExp adaptation hell...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144386@lists.php.net to get a copy of this message
Okay, how about: $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:(http://www.test.org)([^}]+)}([^{]+){/hl}|','<a href="$1$2">$3'.$offsite_img.'</a>',$foo); -- der Ritter aka: Jason k Larson speedfreak@chello.be wrote:
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 (#144386) next »