例如我有一個字符串,像這樣:更改相對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