Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP从URL获取文件夹结构_Php_Url - Fatal编程技术网

使用PHP从URL获取文件夹结构

使用PHP从URL获取文件夹结构,php,url,Php,Url,我试图从URL的路径中只获取文件夹结构,但我不能完全解决它 我尝试过使用parse_url,但这让我了解了整个路径,从那里我尝试过使用explode和regex方法,但我尝试过的方法中没有一个给出了我想要的 URL的示例列表如下: /example.html /folder/example.html /example/folder/example.html /example/folder/two/ 我需要的结果是: / /folder/ /example/folder/ /example/fo

我试图从URL的路径中只获取文件夹结构,但我不能完全解决它

我尝试过使用parse_url,但这让我了解了整个路径,从那里我尝试过使用explode和regex方法,但我尝试过的方法中没有一个给出了我想要的

URL的示例列表如下:

/example.html
/folder/example.html
/example/folder/example.html
/example/folder/two/
我需要的结果是:

/
/folder/
/example/folder/
/example/folder/two/

我可能只是瞎了眼,或者有一个编码器阻塞,所以任何帮助都将不胜感激。

检查我的代码。它会对你有用的

$actual_link = "$_SERVER[REQUEST_URI]";
$fromPath = pathinfo('http://www.domaiName.com/folder/page_folder/file.php'); 
//for dynamic use $actual_link variable in  pathinfo() function

echo $fromPath['dirname']; 

我已经找到了自己的解决方案,很抱歉没有包含我以前的代码

$urls = array('http://example.com/example.html', 'http://example.com/folder/example.html', 'http://example.com/example/folder/example.html', 'http://example.com/example/folder/two/');

foreach ($urls as $url) {
  $url = parse_url($url, PHP_URL_PATH);
  $last_part_position = strrpos($url, "/");
  $url = substr($url, 0, $last_part_position) . '/';
  echo $url.'<br />';
}
$url=array('http://example.com/example.html', 'http://example.com/folder/example.html', 'http://example.com/example/folder/example.html', 'http://example.com/example/folder/two/');
foreach($url作为$url){
$url=parse\u url($url,PHP\u url\u路径);
$last\u part\u position=strrpos($url,“/”);
$url=substr($url,0,$last_part_position)。“/”;
回显$url。“
”; }
请共享您尝试的代码,以便我们可以帮助您。可能已经回答:@marinedea这是一个完全不同的东西,我设法将它进一步缩减,因为我是从字符串传递域的,所以我只需要执行此
echo pathinfo($url,pathinfo_DIRNAME);},谢谢,我甚至都不知道pathinfo()函数现在它可以为您工作了。。。继续发展。。。祝你好运