Re: ? for the Reg Ex people
| From: | Christian Reiniger | Date: | Wed, 07 Feb 2001 21:28:14 +0000 |
| Subject: | Re: ? for the Reg Ex people | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38621@lists.php.net to get a copy of this message | ||
On Wednesday 07 February 2001 21:48, Jason Bryner wrote:
> I'm making a small script that imports HTML pages and I need to do
> some string replacement. I need to replace add a url to all the 'HREF'
> links and images, but if someone could just give me an example of how
> to replace and append the HREF part, I think I can figure it out. It
> needs to find all the variations of HREF, such as 'HREF = "', href="',
> 'href =', etc. So it
> needs to be space and capitalization carefree. THANKS TO ANYONE
> WHO HELPS!!!
$replaced = preg_replace ('/(href\s*=\s*(\'|\"))(.*?)(\\2)/i',
"\\1\\3${urladdition}\\2",
$matches);
On a match, $matches [0] will contain the entire pattern, $matches [1]
the first subpattern (everything from href to the opening quote),
$matches [2] the opening quote char and $matches [3] the URL.
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
"These are the people who proudly call themselves "hackers" --
not as the term is now abused by journalists to mean a computer
criminal, but in its true and original sense of an enthusiast,
an artist, a tinkerer, a problem solver, an expert."
- ESR