Re: regexs - preg_replace
Quote:
Originally posted by Vincent26381
Hi,
I'm trying to filter out links from a webpage but list them at the bottom with this:
preg_replace('/href="([^"]+)"[^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);
It works for <a href="index">bleh</a> but how would i write it that it would also work for single quotes: <a href='index'>bleh</a>
not testing this, but try
preg_replace('/href=["']([^"]+)["'][^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);
that's a bracket with a quote and an apostraphe (may need to be escaped since you are using apostraphe's to define the string). hypothetically, it should match href="..." or href="...' or href='..." or href='...'