0

I have a simple IFrame of another site in my site:

     <iframe name="frame1" src="http://www.walla.co.il" width="100%" height="400"></iframe>

That site doesn't belong to me in any way. I was looking for way go get the exact URL address of that site and post it as an echo so viewers could see the address of that site on my site. I found some scripts online but they didnt seem to work.

Is it even possible to do it? I am just looking for a way to echo it a variable (something like echo $url;)

This is what i've tried so far:

    <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];
    }
    ?>
4

1 回答 1

0

是的,你可以这样做:

$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 字符串应该在一个变量中。类似于查看更新的答案...

于 2013-04-18T19:27:48.130 回答