Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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中从目录的完整路径名中删除起始字符_Php_Directory - Fatal编程技术网

在PHP中从目录的完整路径名中删除起始字符

在PHP中从目录的完整路径名中删除起始字符,php,directory,Php,Directory,我使用上面的方法来获取包含上述脚本的文件夹的完整路径。我想删除字符串的起始部分,以便只获取当前文件夹名称 例如:如果$destination\u path=E:/www/stack;我想从中删除E:/www/以获得唯一的堆栈结果。试试看 $destination_path = getcwd().DIRECTORY_SEPARATOR; getcwd将给出当前工作目录,如果从命令行执行,该目录将是调用执行的php文件的目录或当前工作目录 如果要获取包含此特定代码的文件的目录,请使用 $desti

我使用上面的方法来获取包含上述脚本的文件夹的完整路径。我想删除字符串的起始部分,以便只获取当前文件夹名称

例如:如果$destination\u path=E:/www/stack;我想从中删除E:/www/以获得唯一的堆栈结果。

试试看

$destination_path = getcwd().DIRECTORY_SEPARATOR;
getcwd
将给出
当前工作目录
,如果从命令行执行,该目录将是调用执行的php文件的目录或
当前工作目录

如果要获取包含此特定代码的文件的目录,请使用

$destination_path = getcwd().DIRECTORY_SEPARATOR;
$folder = basename($destination_path);

按照什么逻辑-你想总是上升一级吗?我只需要脚本所在的目录名。
$destination_path = dirname(__FILE__).DIRECTORY_SEPARATOR;
$folder = basename($destination_path);