如何在php中获取没有文件名的文件路径?

时间:2014-03-10 14:54:12

标签: php

例如,这是$ _SERVER ['HTTP_HOST']。 $ _SERVER ['REQUEST_URI']输出:

example.com/foldername/subfolder/controller/index.php

我想以example.com/foldername/subfolder/controller /

结束

谢谢..

3 个答案:

答案 0 :(得分:0)

查看http://php.net/manual/en/function.pathinfo.php

<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>

该输出将是

/www/htdocs/inc
lib.inc.php
php
lib.inc

因此,简而言之,您可以使用$path_parts['dirname']

答案 1 :(得分:0)

答案 2 :(得分:0)

将两者合在一起以获得

$url = "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];