我有這個網址...無法添加http:// mainserver/all(href | action | src)=,讓我陷入困境!
$output = "href=\"/one/two/three\"
href=\"one/two/three\"
src=\"windows.jpg\"
action=\"http://www.google.com/docs\"";
當我申請正則表達式:
$base_url_page = "http://mainserver/";
$output = preg_replace("/(href|src|action)(\s*)=(\s*)(\"|\')(\/+|\/*)(.*)(\"|\')/ismU", "$1=\"" . $base_url_page . "$6\"", $output);
我得到這個:
$output = "href=\"http://mainserver/one/two/three\"
href=\"http://mainserver/one/two/three\"
src=\"http://mainserver/windows.jpg\"
action=\"http://mainserver/http://www.google.com/docs\"";
如何修改正則表達式,以防止這個:http://mainserver/http://www.google.com/ ???????
在HTML與正則表達式解析幾點建議:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2010-11-16 02:18:22
將它只需使用['BASE'元素](http://www.w3.org/TR/html4/struct/links.html#edef-BASE)更改基本URI即可? – Gumbo 2010-11-16 17:18:03