Why don't you just do this in .htaccess, or set a <base href=.../>? What you're trying to fix shouldn't really be done that way. However, you can src=\"(/?) to just assume another localized request.
If you really want a semi-decent way to grab and rewrite your links:
Code:
$preg = "/[\s]+[^>]*?src[\s]?=[\s\"\']+(.*?)[\"\']+.*?>/i";
preg_match_all($preg, $all_of_content_here, $outvar, PREG_PATTERN_ORDER);
Then just walk that to fix all hrefs. You can preg, or ereg if you want. I'll try to make that easy for ya with the following sample
Code:
foreach ($outvar as $imgsrc) {
if (eregi($domain, $imgsrc)) {
// is complete
} elseif (eregi("^/", $imgsrc)) {
// starts with a /
} else {
// assume it's local
}
}