例如,这是$ _SERVER ['HTTP_HOST']。 $ _SERVER ['REQUEST_URI']输出:
example.com/foldername/subfolder/controller/index.php
我想以example.com/foldername/subfolder/controller /
结束谢谢..
答案 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)
print_r( $_SERVER );
http://www.php.net/manual/en/reserved.variables.server.php http://www.php.net/manual/en/language.constants.predefined.php
PATH_TRANSLATED or __DIR__
很多选项=)
答案 2 :(得分:0)
将两者合在一起以获得
$url = "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];