I'm useless with regular expressions and haven't been able to google myself a clear solution to this one.
I want to search+replace some text ($content) for any url inside the anchor's href with a new url (stored as the variable $newurl).
Change this:
<a href="http://blogurl.com/files/foobar.jpg"><img alt="foobar" src="http://blogurl.com/files/2011/03/foobar_thumb.jpg" /></a>
To this:
<a href="http://newurl.com/here/"><img alt="foobar" src="http://blogurl.com/files/2011/03/foobar_thumb.jpg" /></a>
I imagine using preg_replace would be best for this. Something like:
preg_replace('Look for href="any-url"',
'href="$newurl"',$content);
The idea is to get all images on a WordPress front page to link to their posts instead of to full sized images (which is how they default). Usually there would be only one url to replace, but I don't think it would hurt to replace all potential matches.
Hope all that made sense and thanks in advance!