Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: 预定义常量 - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 预定义常量

2025-04-27

预定义常量

DIRECTORY_SEPARATOR (string)
PATH_SEPARATOR (string)
Windows 上使用分号,除此之外使用冒号。
SCANDIR_SORT_ASCENDING (int)
SCANDIR_SORT_DESCENDING (int)
SCANDIR_SORT_NONE (int)
添加备注

用户贡献的备注 2 notes

up
38
Anonymous
10 years ago
In PHP 5.6 you can make a variadic function.

<?php
/**
* Builds a file path with the appropriate directory separator.
* @param string $segments,... unlimited number of path segments
* @return string Path
*/
function file_build_path(...$segments) {
return
join(DIRECTORY_SEPARATOR, $segments);
}

file_build_path("home", "alice", "Documents", "example.txt");
?>

In earlier PHP versions you can use func_get_args.

<?php
function file_build_path() {
return
join(DIRECTORY_SEPARATOR, func_get_args($segments));
}

file_build_path("home", "alice", "Documents", "example.txt");
?>
up
31
Anonymous
11 years ago
For my part I'll continue to use this constant because it seems more future safe and flexible, even if Windows installations currently convert the paths magically. Not that syntax aesthetics matter but I think it can be made to look attractive:

<?php
$path
= join(DIRECTORY_SEPARATOR, array('root', 'lib', 'file.php');
?>

官方地址:https://www.php.net/manual/en/dir.constants.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3