php 函数
strtotime() 函数
定义和用法
strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。
语法
strtotime(time,now)
参数 | 描述 |
---|---|
time | 规定要解析的时间字符串。 |
now | 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 |
说明
该函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数,则用系统当前时间。
该函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_timezone_get() 函数页面中有说明。
返回值
成功则返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前本函数在失败时返回 -1
<?php echo(strtotime("now")); echo(strtotime("3 October 2005")); echo(strtotime("+5 hours")); echo(strtotime("+1 week")); echo(strtotime("+1 week 3 days 7 hours 5 seconds")); echo(strtotime("next Monday")); echo(strtotime("last Sunday")); ?>
PHP parse_str() 函数
定义和用法
parse_str() 函数把查询字符串解析到变量中。
语法
parse_str(string,array)
参数 | 描述 |
---|---|
string | 必需。规定要解析的字符串。 |
array | 可选。规定存储变量的数组名称。该参数指示变量存储到数组中。 |
提示和注释
注释:如果未设置 array 参数,由该函数设置的变量将覆盖已由同名变量。
注释:php.ini 中的 magic_quotes_gpc 设置影响该函数的输出。如果已启用,那么在 parse_str() 解析之前,变量会被addslashes() 转换。
例子
例子 1
<?php parse_str("id=23&name=John%20Adams"); echo $id."<br />"; echo $name; ?>
输出:
23 John Adams
例子 2
<?php parse_str("id=23&name=John%20Adams",$myArray); print_r($myArray); ?>
输出:
Array ( [id] => 23 [name] => John Adams )