2013-10-02 186 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 –