-1

我正在尝试从 html 页面获取确切的域 url

我尝试这个 url 只从 v.html 返回

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

但我的 php 函数显示所有网址

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
4

2 回答 2

0

strpos()在其输出中使用 PHP 函数。与他一起搜索“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; 
   } 
}
于 2013-10-02T01:27:01.220 回答
-1

使用 JavaScript,您可以使用

this.document.location.href

于 2013-10-02T01:13:32.930 回答