$content = '<!--<sup><span style="font-weight:bold;color:black;">0</span></sup><br/>-->
<div class="popular-video-image">
<a href="video/Far+East+Movement - Like+a+G6/w4s6H4ku6ZY/" title="<lang video_go_to=Far East Movement - Like a G6>">
<img src="/images/topvideo/1.jpg" alt=""/>
</a>
<span class="popular-video-artist ellipsis"><a href="video/Far+East+Movement - Like+a+G6/w4s6H4ku6ZY/" title="<lang video_go_to=Far East Movement - Like a G6>" class="ellipsis">Far East Movement</a></span>
<span class="popular-video-title ellipsis"><a href="video/Far+East+Movement - Like+a+G6/w4s6H4ku6ZY/" title="<lang video_go_to=Far East Movement - Like a G6>" class="ellipsis">Like a G6</a></span>
</div>';
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->loadHTML($content);
foreach ($dom->getElementsByTagName('a') as $node)
{
$node->setAttribute('href', 'http://mysite.ru/' . $node->getAttribute('href'));
}
$dom->formatOutput = true;
echo $dom->saveXml($dom->documentElement);
<html>
<body>
<div class="popular-video-image">
<a href="http://mysite.ru/video/Far+East+Movement - Like+a+G6/w4s6H4ku6ZY/" title="<lang video_go_to=Far East Movement - Like a G6>">
<img src="/images/topvideo/1.jpg" alt=""/></a>
<span class="popular-video-artist ellipsis"><a href="http://mysite.ru/video/Far+East+Movement - Like+a+G6/w4s6H4ku6ZY/" title="<lang video_go_to=Far East Movement - Like a G6>" class="ellipsis">Far East Movement</a></span>
<span class="popular-video-title ellipsis"><a href="http://mysite.ru/video/Far+East+Movement - Like+a+G6/w4s6H4ku6ZY/" title="<lang video_go_to=Far East Movement - Like a G6>" class="ellipsis">Like a G6</a></span>
</div>
</body>
</html>
我不想添加HTML和body標籤。也不想將標籤替換爲<lang>
。 And
也是不必要的。
我希望收到此類內容,這是在入口處,只有修改的鏈接..
對不起,我的英語不好!
的loadXML不顯示除錯誤什麼 – Isis 2010-11-27 12:17:54
好吧,也許錯誤可以固定? :) – Jon 2010-11-27 12:19:44