根据Id从远程站点获取iframe源代码


Get an iframe source code from remote site based on Id

我想从远程站点获取iframe的源代码,然后将其返回到我的站点。我认为最好的方法是通过php或者通过php-Dom或者像simple_html_Dom_parser这样的库。

这是我的尝试:

<?php
  include_once('simple_html_dom.php');
  $url = ('http://remotesite);          
  $html = file_get_html($url);                                 
  $content = $html->find('iframe#target',0);
  echo $content;
?>

但这给我带来了

<iframe allowtransparency="true" id="target"  scrolling="no" width="650">  </iframe>

然而,远程站点中的iframe是这样的:

<iframe allowTransparency="true" id="target" scrolling="no" width="650" allowtransparency="no" frameborder="0" src="domain.com/page.html" height="500"> </iframe>

我的方法出了什么问题?

这应该有效:

echo htmlentities($iframe->ownerDocument->saveXML($iframe));