例如我有一个字符串,像这样:更改相对URL绝对URL
$html = '
<a href="test.html">test</a>
<a href="http://mydomain.com/test.html">test</a>
<a href="http://otherdomain.com/test.html">test</a>
<a href="someothertest/otherdir/hi.html">hi</a>
';
,我想绝对URL追加到没有abolute域给出所有的HREF。
$html = '
<a href="http://mydomain.com/test.html">test</a>
<a href="http://mydomain.com/test.html">test</a>
<a href="http://otherdomain.com/test.html">test</a>
<a href="http://mydomain.com/someothertest/otherdir/hi.html">hi</a>
';
最好的办法是做什么?我想用正则表达式,但我的RegEx技能是**;)
在此先感谢!
虽然正则表达式可以让你去暂且可以在以后很危险时间点。最好将它解析为xml,检查属性是以“http://”开头,如果不是,则前置'http:// mydomain.com /'。 – Amarghosh 2010-07-27 11:05:11
test应该被添加到示例中... – Hinek 2010-07-27 14:43:57