http://somedomain.com
をどこから拾ってくるかですね
$_SERVER["SERVER_NAME"]あたりを利用しますか?
またパスも
href='/aa/bb'
ならいいですが
href='aa/bb'
となっている場合、カレントからの相対位置になるので工夫が必要
とりあえず拾い方はこうすればいいでしょう。
PHP
1
2$html=<<<eof
3<a href="test.htm">test1</a>
4<a href='/test/test.htm'>test2</a>
5<a href="http://exsample.com/test.htm">test3</a>
6<a href='https://exsample.com/test/test.htm'>test4</a>
7eof;
8
9$pattern="/(?<=href=([\"']))(?!https?:\/\/).+?(?=\\1)/mis";
10preg_match_all($pattern,$html,$match);
11print_r($match[0]);
12
参考までに
PHP
1$html=<<<eof
2<a href="test.htm">test1</a>
3<a href='/test/test.htm'>test2</a>
4<a href='../test/test.htm'>test3</a>
5eof;
6
7$pattern="/(?<=href=([\"']))(?!https?:\/\/).+?(?=\\1)/mis";
8preg_match_all($pattern,$html,$match);
9print_r($match[0]);
10
11$replacement=function($match){
12 $path =$_SERVER["REQUEST_SCHEME"]."://";
13 $path.=$_SERVER["SERVER_NAME"];
14 if(!preg_match("|^/|",$match[0])){
15 $path.=dirname($_SERVER["REQUEST_URI"])."/";
16 }
17 return $path.$match[0];
18};
19$html=preg_replace_callback($pattern,$replacement,$html);
20print "<pre>";
21print htmlspecialchars($html);