RegExp adaptation hell...

From: Date: Fri, 18 Apr 2003 02:42:32 +0000
Subject: RegExp adaptation hell...
Groups: php.general 
Request: Send a blank email to php-general+get-144363@lists.php.net to get a copy of this message
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 (#144363) next »