php開發常用函數總結
08-17
php開發常用函數總結
推薦閱讀:
1
23456
78910http_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
234567
891011121314151617
181920212223mktime()
<?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
345678910mb_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
23
456789101112strip_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
234567891011array_push()
<?php
$a=array();
array_push($a,"blue","yellow");
print_r($a);
?>
Array
(
[0] => blue
[1] => yellow
)
1
234567891011121314array_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
2345mb_substr()
<?php
$aaa = "this這是中文字元串";
echo
mb_substr($aaa,0,6,UTF-8);//輸出值為: this這是
1
234strtotime
<?php
echo
strtotime(date("Y-m-d",time())); //1483632000
1
234567891011121314intval() 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"
>>>>閱讀全文 推薦閱讀:
※§12.PHP會話技術
※php 靜態方法和靜態屬性及其調用方式
※phpstorm有哪些好用的插件 ?
※請搭配世界上最好的語言使用 - 「Angel框架發表書」