I think PHP is useless, bacause iframe inserted after php execution, or am I mistaken?
So, the only solution I know about is using Javascript / jQuery.
eg. this will work if JS is on the same page as the iframe:
<html> <head> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script> <script type="text/javascript"> $(function() { var myContent = $("#iFrame").contents().find("#myContent") }); </script> </head> <body> <iframe src="mifile.html" id="iFrame" style="width:200px;height:70px;border:dotted 1px red" frameborder="0"> <div id="myContent"> iframe content blablabla </div> </iframe> </body> </html>
However, I use the Simple HTML DOM library to capture a remote web page, for example:
$url = 'http://page-with-some-iframe.com/'; $html = file_get_html( $url ); // Find iframes and put them in an array $iframes_arr = array(); foreach($html->find('iframe') as $element) { $iframes_arr[] = $element->outertext; } var_dump($iframes_arr); die();
But obviously, nothing is returned: (, because iframes are displayed after php starts; (
So, I thought that I probably would need to enter this code:
<script type="text/javascript"> $(function() { var myContent = $("#iFrame").contents().find("#myContent") }); </script>
in the header of my captured page stored in $ html.
Any idea how to get iframe content like this, or is this an overly complicated approach, and is there a simpler solution?
user2405063
source share