我正在尝试解决问题,我正在获取远程页面的html源代码,此代码包含如下所示的链接:
<a href='javascript:openWindow("index1.php?option=com_lsh&view=lsh&event_id=156029&tv_id=848&tid=34928&channel=0&tmpl=component&layout=popup&Itemid=335","735","820")' >Link#1</a>
我想编辑此类链接,然后在我的页面上回显它,使其在新标签页中打开,而不是在新窗口中打开。
我获取带有文件获取内容的远程页面源如下:
<?php
//Get the url
$url = "http://remote.com/static/section0.html";
$html = file_get_contents($url);
$doc = new DOMDocument(); // create DOMDocument
libxml_use_internal_errors(true);
$doc->loadHTML($html); // load HTML you can add $html
$elements = $doc->getElementsByTagName('tbody');
$toRemove = array();
// gather a list of tbodys to remove
foreach($elements as $el)
if((strpos($el->nodeValue, 'desktop') !== false) && !in_array($el->parentNode, $toRemove, true))
$toRemove[] = $el->parentNode;
foreach($elements as $el)
if((strpos($el->nodeValue, 'Recommended') !== false) && !in_array($el->parentNode, $toRemove, true))
$toRemove[] = $el->parentNode;
// remove them
foreach($toRemove as $tbody)
$tbody->parentNode->removeChild($tbody);
echo str_replace('</h3><table','<table',$doc->saveHTML());
?>
如你所见,我也对代码做了一些其他的修改,但我无法将新窗口转换为新标签
任何想法?