我的站点中有另一个站点的简单IFrame:
<iframe name="frame1" src="http://www.walla.co.il" width="100%" height="400"></iframe>那个网站无论如何都不属于我。我正在寻找方法去获得该网站的确切URL地址,并将其作为回声发布,这样观众就可以在我的网站上看到该网站的地址。我在网上找到了一些脚本,但它们似乎不起作用。
有没有可能做到呢?我只是在寻找一种回显变量的方法(比如echo $url;)
这就是我到目前为止所尝试的:
<iframe name="frame1" src="http://www.walla.co.il" width="100%" height="400"></iframe>
<?php
$htmlPage = file_get_contents("http://www.walla.co.il"); //the page has the iframe
if(preg_match_all("/<iframe[^>]*name=\"frame1\"[^>]*src=\"([^\"]+)\"[^>]*>/i", $htmlPage, $matches))
{
print_r($matches);
echo $matches[1][0];
}
?>发布于 2013-04-19 03:27:48
是的,你可以这样做:
$htmlPage = '<iframe name="frame1" src="http://www.walla.co.il" width="100%" height="400"></iframe>'; //the page has the iframe
if(preg_match_all("/<iframe[^>]*name=\"frame1\"[^>]*src=\"([^\"]+)\"[^>]*>/i", $htmlPage, $matches))
{
//print_r($matches);
echo $matches[1][0];
}这还没有经过测试...
编辑:我不知道你想在这里完成什么,但你不能那样做。iframe的html字符串应该在变量中。类似于查看更新后的答案...
https://stackoverflow.com/questions/16091396
复制相似问题