php正则表达式替换html中的超链接为绝对地址

468
$html = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#", '$1http://mydomain.com/$2$3', $html);

you can use (?!http|mailto) if you have also mailto links in your $html

Post Comment