Php 如何从页面获取域Url

Php 如何从页面获取域Url,php,html,preg-match,Php,Html,Preg Match,我正在尝试从html页面获取准确的域url 我尝试此url仅从v.html返回 https://picasaweb.google.com/114948445121686813006/DropBox?authkey=Gv1sRgCMLjxpef1rHJ3QE#5929911272604125650 但是我的php函数显示所有URL v、 html有html代码和链接 这是我的php代码 <?php $string=file_get_contents("v.html"); functi

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

我尝试此url仅从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 />';
 }


?>

使用JavaScript,您可以使用


this.document.location.href

在其输出端使用PHP函数
strpos()
。 和他一起搜索“https”并找到你的URL

$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; 
   } 
}

pica有一个api,你为什么要抓取?上传后我没有得到获取照片url的文档。他要求使用PHP而不是JS。@user0000001他的第一行说“我正在尝试从html页面获取准确的域url”。这并不意味着php,而且您很少在独立于js和cssi的情况下开发php。我已经这样做了。我只希望此url返回此url将始终保持不变,或者有时会发生变化@user2489961?authkey=about将更改其他将相同您始终可以获得不随strpos()更改的变量的一部分,如“picasaweb.google.com”,然后从那里计算stringTry的开始和结束:
foreach($url作为$url){if(strstr($url,'picasaweb.google.com'){echo$url;}}
foreach($urls as $url) { 
   if (strstr($url,'picasaweb.google.com')) { 
      echo $url; 
   } 
}