2013-04-18 25 views
0

我有其他網站的一個簡單的IFrame在我的網站:獲取從一個IFrame的URL地址在我的網站使用PHP

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

網站不屬於我以任何方式。我一直在尋找方法去獲取該網站的確切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]; 
    } 
    ?> 

回答

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字符串應該在變量內。像看到更新的答案...

+0

似乎沒有工作,謝謝你的嘗試。 – user1938653

+0

它適用於「