无需言 做自己 业 ,精于勤 荒于嬉.

目录函数 rewinddir 倒回目录句柄

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

rewinddir

(PHP 4, PHP 5, PHP 7, PHP 8)

rewinddir倒回目录句柄

说明

rewinddir(resource $dir_handle): void

dir_handle 指定的目录流重置到目录的开头。

参数

dir_handle

目录句柄的 resource,之前由 opendir() 打开

阅读全文 »

目录函数 getcwd 取得当前工作目录

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
<?php 
// current directory
echo getcwd() . "\n";
chdir('cvs');
// current directory
echo getcwd() . "\n";
?>

阅读全文 »

目录函数 scandir 列出指定路径中的文件和目录

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
<?php 
$dir    = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
?>

      示例2
<?php 
$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}
sort($files);
print_r($files);
rsort($files);
print_r($files);
?>

阅读全文 »

目录函数 chdir 改变目录

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
<?php 
// current directory
echo getcwd() . "\n";
chdir('public_html');
// current directorye
cho getcwd() . "\n";
?>

阅读全文 »

目录函数 chroot 改变根目录

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
<?php 
chroot("/path/to/your/chroot/");
echo getcwd();
?>

阅读全文 »

目录函数 opendir 打开目录句柄

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
<?php 
$dir = "/etc/php5/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    }
}
?>

阅读全文 »

目录函数 readdir 从目录句柄中读取条目

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
<?php 
// 注意在 4.0.0-RC2 之前不存在 !== 运算符
if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";
    /* 这是正确地遍历目录方法 */
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }
    /* 这是错误地遍历目录的方法 */
    while ($file = readdir($handle)) {
        echo "$file\n";
    }
    closedir($handle);
}
?>
      示例2
<?php 
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

阅读全文 »

Date/Time 函数 strtotime 将任何字符串的日期时间描述解析为 Unix 时间戳

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>

      示例2
<?php 
$str = 'Not Good';
// PHP 5.1.0 之前的版本中和应该改成和 -1 进行比较if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
}
 else {
    echo "$str == " . date('l dS of F Y h:i:s A', $timestamp);
}
?>

阅读全文 »

Date/Time 函数 localtime 取得本地时间

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
$localtime = localtime();
$localtime_assoc = localtime(time(), true);
print_r($localtime);
print_r($localtime_assoc);
?>

阅读全文 »

Date/Time 函数 time 返回当前的 Unix 时间戳

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
$nextWeek = time() + (7 * 24 * 60 * 60);
                   // 7 days;
 24 hours;
 60 mins;
 60 secsecho 'Now:       '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
// or using strtotime():echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";
?>

阅读全文 »

Date/Time 函数 strptime 解析由 strftime() 生成的日期/时间

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
$format = '%d/%m/%Y %H:%M:%S';
$strf = strftime($format);
echo "$strf\n";
print_r(strptime($strf, $format));
?>

阅读全文 »

Date/Time 函数 strftime 根据区域设置格式化本地时间/日期

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
setlocale(LC_TIME, "C");
echo strftime("%A");
setlocale(LC_TIME, "fi_FI");
echo strftime(" in Finnish is %A,");
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
setlocale(LC_TIME, "de_DE");
echo strftime(" in German %A.\n");
?>

      示例2
<?php 
/*     December 2002 / January 2003ISOWk  M   Tu  W   Thu F   Sa  Su----- ----------------------------51     16  17  18  19  20  21  2252     23  24  25  26  27  28  291      30  31   1   2   3   4   52       6   7   8   9  10  11  123      13  14  15  16  17  18  19   */
// 输出: 12/28/2002 - %V,%G,%Y = 52,2002,2002echo "12/28/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y", strtotime("12/28/2002")) . "\n";
// 输出: 12/30/2002 - %V,%G,%Y = 1,2003,2002echo "12/30/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y", strtotime("12/30/2002")) . "\n";
// 输出: 1/3/2003 - %V,%G,%Y = 1,2003,2003echo "1/3/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2003")) . "\n";
// 输出: 1/10/2003 - %V,%G,%Y = 2,2003,2003echo "1/10/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/10/2003")) . "\n";
/*     December 2004 / January 2005ISOWk  M   Tu  W   Thu F   Sa  Su----- ----------------------------51     13  14  15  16  17  18  1952     20  21  22  23  24  25  2653     27  28  29  30  31   1   21       3   4   5   6   7   8   92      10  11  12  13  14  15  16   */
// 输出: 12/23/2004 - %V,%G,%Y = 52,2004,2004echo "12/23/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/23/2004")) . "\n";
// 输出: 12/31/2004 - %V,%G,%Y = 53,2004,2004echo "12/31/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/31/2004")) . "\n";
// 输出: 1/2/2005 - %V,%G,%Y = 53,2004,2005echo "1/2/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/2/2005")) . "\n";
// 输出: 1/3/2005 - %V,%G,%Y = 1,2005,2005echo "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n";
?>

      示例3
<?php 
// Jan 1: results in: '%e%1%' (%%, e, %%, %e, %%)$format = '%%e%%%e%%';
// Check for Windows to find and replace the %e // modifier correctlyif (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
    $format = preg_replace('#(?<!%)((?:%%)*)%e#', '</refsect1>%#d', $format);
}
echo strftime($format);
?>

      示例4
<?php 
// Describe the formats.$strftimeFormats = array(    'A' => 'A full textual representation of the day',    'B' => 'Full month name, based on the locale',    'C' => 'Two digit representation of the century (year divided by 100, truncated to an integer)',    'D' => 'Same as "%m/%d/%y"',    'E' => '',    'F' => 'Same as "%Y-%m-%d"',    'G' => 'The full four-digit version of %g',    'H' => 'Two digit representation of the hour in 24-hour format',    'I' => 'Two digit representation of the hour in 12-hour format',    'J' => '',    'K' => '',    'L' => '',    'M' => 'Two digit representation of the minute',    'N' => '',    'O' => '',    'P' => 'lower-case "am" or "pm" based on the given time',    'Q' => '',    'R' => 'Same as "%H:%M"',    'S' => 'Two digit representation of the second',    'T' => 'Same as "%H:%M:%S"',    'U' => 'Week number of the given year, starting with the first Sunday as the first week',    'V' => 'ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week',    'W' => 'A numeric representation of the week of the year, starting with the first Monday as the first week',    'X' => 'Preferred time representation based on locale, without the date',    'Y' => 'Four digit representation for the year',    'Z' => 'The time zone offset/abbreviation option NOT given by %z (depends on operating system)',    'a' => 'An abbreviated textual representation of the day',    'b' => 'Abbreviated month name, based on the locale',    'c' => 'Preferred date and time stamp based on local',    'd' => 'Two-digit day of the month (with leading zeros)',    'e' => 'Day of the month, with a space preceding single digits',    'f' => '',    'g' => 'Two digit representation of the year going by ISO-8601:1988 standards (see %V)',    'h' => 'Abbreviated month name, based on the locale (an alias of %b)',    'i' => '',    'j' => 'Day of the year, 3 digits with leading zeros',    'k' => '',    'l' => 'Hour in 12-hour format, with a space preceeding single digits',    'm' => 'Two digit representation of the month',    'n' => 'A newline character ("\n")',    'o' => '',    'p' => 'UPPER-CASE "AM" or "PM" based on the given time',    'q' => '',    'r' => 'Same as "%I:%M:%S %p"',    's' => 'Unix Epoch Time timestamp',    't' => 'A Tab character ("\t")',    'u' => 'ISO-8601 numeric representation of the day of the week',    'v' => '',    'w' => 'Numeric representation of the day of the week',    'x' => 'Preferred date representation based on locale, without the time',    'y' => 'Two digit representation of the year',    'z' => 'Either the time zone offset from UTC or the abbreviation (depends on operating system)',    '%' => 'A literal percentage character ("%")',);
// Results.$strftimeValues = array();
// Evaluate the formats whilst suppressing any errors.foreach($strftimeFormats as $format => $description){
    if (False !== ($value = @strftime("%{
$format}
"))){
        $strftimeValues[$format] = $value;
    }
}
// Find the longest value.$maxValueLength = 2 + max(array_map('strlen', $strftimeValues));
// Report known formats.foreach($strftimeValues as $format => $value){
    echo "Known format   : '{
$format}
' = ", str_pad("'{
$value}
'", $maxValueLength), " ( {
$strftimeFormats[$format]}
 )\n";
}
// Report unknown formats.foreach(array_diff_key($strftimeFormats, $strftimeValues) as $format => $description){
    echo "Unknown format : '{
$format}
'   ", str_pad(' ', $maxValueLength), ($description ? " ( {
$description}
 )" : ''), "\n";
}
?>

阅读全文 »

Date/Time 函数 timezone_abbreviations_list 别名 DateTimeZone::listAbbreviations()

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

timezone_abbreviations_list

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

timezone_abbreviations_list别名 DateTimeZone::listAbbreviations()

说明

此函数是该函数的别名: DateTimeZone::listAbbreviations()

阅读全文 »

Date/Time 函数 mktime 取得一个日期的 Unix 时间戳

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
// Set the default timezone to use. Available as of PHP 5.1date_default_timezone_set('UTC');
// Prints: July 1, 2000 is on a Saturdayecho "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
// Prints something like: 2006-04-05T01:02:03+00:00echo date('c', mktime(1, 2, 3, 4, 5, 2006));
?>

      示例2
<?php 
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997));
echo date("M-d-Y", mktime(0, 0, 0, 13, 1, 1997));
echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 1998));
echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 98));
?>

      示例3
<?php 
$lastday = mktime(0, 0, 0, 3, 0, 2000);
echo strftime("Last day in Feb 2000 is: %d", $lastday);
$lastday = mktime(0, 0, 0, 4, -31, 2000);
echo strftime("Last day in Feb 2000 is: %d", $lastday);
?>

阅读全文 »

Date/Time 函数 timezone_name_from_abbr Returns the timezone name from abbreviation

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
echo timezone_name_from_abbr("CET") . "\n";
echo timezone_name_from_abbr("", 3600, 0) . "\n";
?>

阅读全文 »

Date/Time 函数 timezone_location_get 别名 DateTimeZone::getLocation()

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

timezone_location_get

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

timezone_location_get别名 DateTimeZone::getLocation()

说明

此函数是该函数的别名: DateTimeZone::getLocation()

阅读全文 »

Date/Time 函数 timezone_identifiers_list 别名 DateTimeZone::listIdentifiers()

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

timezone_identifiers_list

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

timezone_identifiers_list别名 DateTimeZone::listIdentifiers()

说明

此函数是该函数的别名: DateTimeZone::listIdentifiers()

阅读全文 »

Date/Time 函数 timezone_offset_get 别名 DateTimeZone::getOffset()

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

timezone_offset_get

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

timezone_offset_get别名 DateTimeZone::getOffset()

说明

此函数是该函数的别名: DateTimeZone::getOffset()

阅读全文 »

Date/Time 函数 timezone_open 别名 DateTimeZone::__construct()

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

timezone_open

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

timezone_open别名 DateTimeZone::__construct()

说明

此函数是该函数的别名: DateTimeZone::__construct()

阅读全文 »

Date/Time 函数 timezone_version_get 获取 timezonedb 的版本

发表日期:2021-07-01 08:55:28 | 来源: | 分类:Date/Time 函数

      示例1
<?php 
echo timezone_version_get();
?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。