2013-10-02 184 views
-1

我試圖從HTML頁面獲取精確的域名網址如何獲取域名網址從頁

我想這個網址從v.html

https://picasaweb.google.com/114948445121686813006/DropBox?authkey=Gv1sRgCMLjxpef1rHJ3QE#5929911272604125650 

回來,但我的PHP函數顯示所有URL

v.html有HTML代碼和鏈接

這是我的PHP代碼

<?php 


$string=file_get_contents("v.html"); 

function getUrls($string) 
{ 
    $regex = '/https?\:\/\/[^\" ]+/i'; 
    preg_match_all($regex, $string, $matches); 
    return ($matches[0]); 
} 

$urls = getUrls($string); 

foreach($urls as $url) 
{ 
    echo $url.'<br />'; 
} 


?> 

輸出

http://www.w3.org/2007/app 
http://schemas.google.com/photos/2007 
http://www.w3.org/2005/Atom 
http://purl.org/atom/app# 
http://www.w3.org/2007/app 
http://schemas.google.com/photos/2007 
http://www.w3.org/2005/Atom 
http://purl.org/atom/app# 
http://www.w3.org/2007/app 
http://www.w3.org/2005/Atom 
http://purl.org/atom/app# 
http://www.w3.org/2007/app 
https://picasaweb.google.com/114948445121686813006/DropBox?authkey=Gv1sRgCMLjxpef1rHJ3QE#5929911272604125650 
+0

異食癖有一個API,你爲什麼刮? – 2013-10-02 01:13:37

+0

上傳後我沒有獲取獲取照片url的文檔 – user2489961

回答

0

使用PHP函數strpos()。 隨着他搜索 「https」 開頭,並找到自己的網址

$findme = 'https://'; 
$pos = strpos($output, $findme); 

// Note our use of ===. Simply == would not work as expected 
if ($pos === false) { 
    // not found in the output 
} else { 
    // found in the output 
} 

或試試這個:

foreach($urls as $url) { 
    if (strstr($url,'picasaweb.google.com')) { 
     echo $url; 
    } 
} 
+0

我已經做了這個我只是想這個url返回 https://picasaweb.google.com/114948445121686813006/DropBox?authkey=Gv1sRgCMLjxpef1rHJ3QE#5929911272604125650 – user2489961

+0

此URL將始終保持不變,或者有時會變化@ user2489961? –

+0

authkey = abcd將chnage其他將相同 – user2489961

-1

使用JavaScript你可以得到使用

在其輸出端this.document.location.href

+0

他要求使用PHP而不是JS。 – VladHQ

+0

@ user0000001他的第一行說「我試圖從html頁面獲得確切的域名url」。這並不意味着PHP,並且很少你開發PHP的隔離js和css –