Re: RegEx

From: Date: Tue, 27 May 2003 12:37:57 +0000
Subject: Re: RegEx
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149098@lists.php.net to get a copy of this message
Ok, so I obviously need to start reading up on RegEx's thank you Ernest for you help with the last one. So far I have this: $siteurl = "http://domain.com"; $string = join('', file($siteurl)); $matches = array(); $re = '|<!--\*{5,5} BEGIN HOME PAGE CONTENT \*{5,5} -->' . '(.*?)' . '<!--\*{5,5} END HOME PAGE CONTENT \*{5,5} -->|is'; preg_match_all($re, $string, $matches); $string = $matches[0][0]; $output = preg_replace('/(<img.*?src=")([^"]+)("[^>]+>)/',"\1$siteurl\2\3",$string); $output = preg_replace('~(src=|href=|SRC=)("|\')(?!href://)(.*?)(\2)~','\1\2'.$siteurl.'\3\4',$string); echo $output; At this point I'm trying to replace the relative url's with absolute url's. More specifically either all occurances of src="/graphics and href="/race with src="http://domain.com/graphic and href="http://domain.com/race respectively OR to simply skip a few instances where there already exists an absolute URL so I do not end up with http://domain.comhttp://images.domain.com/images/ The reg ex above is hacked together from examples and it seems to work fine for replacing ALL occurances but I need it to be a little more specific as mentioned above and have not been able to modify it correctly on my own..

« previous php.general (#149098) next »