$pat = "/(<img[^>]*src\s*=\s*[\"\'])(\/.*)([\"\'])/"; $repl = "\\1http://domain.name\\2\\3"; preg_replace($pat, $repl, $html);