RE: [PHP] preg_replace Problem

From: Date: Mon, 30 Oct 2000 22:24:12 +0000
Subject: RE: [PHP] preg_replace Problem
Groups: php.general 
Request: Send a blank email to php-general+get-22761@lists.php.net to get a copy of this message
I'd suggest using arrays of search replace to do this one, otherwise your reg exp gets out of hand, something like $search = array("|src[\s]*=[\s]*[\"\']?http://|", "|src[\s]*=[\s]*[\"\']?(?!http://)(\/)?|"); $replace = array("src=\"http://", "src=\"http://$host/"); $result = preg_replace($search, $replace, $document); > -----Original Message----- > From: Anarchos [mailto:anarchos@apushardware.com] > Sent: Monday, 30 October 2000 10:53 > To: php-general@lists.php.net > Subject: [PHP] preg_replace Problem > > > > preg_replace("src=\"?(^http://)(.*)\"?iU","src=\"http://www. > blah.com/\\1\"",$var); > > is the regex that I'm using for an "email this article" > script. It is supposed to take all relative image src's, ie > <img src="images/blah.gif", and append > "http://www.blah.com/" > to them, so that in the replacement it will be: <img > src="http://www.blah.com/images/blah.gif". It is also > > supposed to work when the image src is src=imageSrc, or > src="imageSrc". But it doesn't do anything =(. Any ideas? > > Thanks, > Anarchos >

« previous php.general (#22761) next »