1
2
3
4
5
6
7
8
9
10
|
http_build_query()
<?php
$data = array(
'foo'
=>
'bar'
,
'baz'
=>
'boom'
,
'cow'
=>
'milk'
,
'php'
=>
'hypertext processor'
);
echo
http_build_query($data);
foo=bar&baz=boom&cow=milk&php=hypertext+processor
?>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
mktime()
<?php
//
输出:October 3, 1975 was on a Friday
echo
"Oct 3, 1975 was on a "
.
date
(
"l"
, mktime(0,0,0,10,3,1975)) .
"<br><br>"
;
//
在进行日期计算和验证时会用到 mktime() 函数
//
它会对超出范围的输入值自动计算正确的值:
echo
date
(
"M-d-Y"
,mktime(0,0,0,12,36,2001)) .
"<br>"
;
echo
date
(
"M-d-Y"
,mktime(0,0,0,14,1,2001)) .
"<br>"
;
echo
date
(
"M-d-Y"
,mktime(0,0,0,1,1,2001)) .
"<br>"
;
echo
date
(
"M-d-Y"
,mktime(0,0,0,1,1,99)) .
"<br>"
;
?>
Oct 3, 1975 was on a Friday
Jan-05-2002
Feb-01-2002
Jan-01-2001
Jan-01-1999
$today=mktime(0,0,0,
date
(
'm'
),
date
(
'd'
),
date
(
'Y'
));
|
1
2
3
4
5
6
7
8
9
10
|
mb_strlen
<?php
//
测试时文件的编码方式要是UTF8
$str=
'中文a字1符'
;
echo
strlen($str).
'<br>'
;
//14
echo
mb_strlen($str,
'utf8'
).
'<br>'
;
//6
echo
mb_strlen($str,
'gbk'
).
'<br>'
;
//8
echo
mb_strlen($str,
'gb2312'
).
'<br>'
;
//10
?>
|
1
2
3
4
5
6
7
8
9
10
11
12
|
strip_tags()
<?php
$text =
'<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'
;
echo
strip_tags($text);
echo
" "
;
//
允许 <p> 和 <a>
echo
strip_tags($text,
'<p><a>'
);
?>
Test paragraph. Other text
<p>Test paragraph.<
/p
> <a href=
"#fragment"
>Other text<
/a
>
|
1
2
3
4
5
6
7
8
9
10
11
|
array_push()
<?php
$a=array();
array_push($a,
"blue"
,
"yellow"
);
print_r($a);
?>
Array
(
[0] => blue
[1] => yellow
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
array_merge()
<?php
$a1=array(
"red"
,
"green"
);
$a2=array(
"blue"
,
"yellow"
);
print_r(array_merge($a1,$a2));
?>
Array
(
[0] => red
[1] => green
[2] => blue
[3] => yellow
)
|
1
2
3
4
5
|
mb_substr()
<?php
$aaa =
"this这是中文字符串"
;
echo
mb_substr($aaa,0,6,
'UTF-8'
);
//
输出值为: this这是
|
1
2
3
4
|
strtotime
<?php
echo
strtotime(
date
(
"Y-m-d"
,
time
()));
//1483632000
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
intval() floatval() strval()
<?php
$str=
"123.9abc"
;
$int = intval($str);
var_dump($int);
$float = floatval($str);
var_dump($float);
$str=strval($str);
var_dump($str);
?>
int(123)
float(123.9)
string(8)
"123.9abc"
|
本文转自ning1022 51CTO博客,原文链接:http://blog.51cto.com/ning1022/1889697
,如需转载请自行联系原作者