## 1. 定義常亮
~~~
define();
const PI = 3.14159;
~~~
## 2.數據類型
~~~
bolean(布爾型) integer(整型) float(浮點型) string(字符串) array(數組) object(對象) resource(資源)
~~~
## 3.布爾型轉換
~~~
(bool)0;false (bool)1;true (bool)-1;true (bool)0.0;false (bool)0.01;true (bool)-0.01;true
(bool)'字符串';true (bool)'';false (bool)'0';false (bool)'0.0';true (bool)' ';true
~~~
## 4.進制轉換
~~~
二進制 sprintf('%b',$str);
八進制 sprintf('O%o',$str);
十六進制 sprintf('OX%x',$str);
~~~
## 5.循環語句
>continue;跳過本次循環
>break;退出當前循環
**while循環**
~~~
$i = 1;
while($i <= 9){
echo $i;
$i++;
}
~~~
**do while循環**
~~~
$i = 1;
do{
echo $i;
$i++;
}while($i <=10);
~~~
>do while循環會先執行一次;
## 5.其他常用
**調用函數外部變量**
~~~
global $name;
~~~
**靜態變量**
~~~
static $num = 0;
~~~
## 6.數組過濾
~~~
array_filter($arr,$function($v){return $v%2==0;});
~~~
## 7.計算字符串相似度百分比
~~~
similar_text($str1,$str2)/strlen($str2)*100.'%';
~~~
## 8.網頁格式化函數
>**將字符串轉換為html實體**
~~~
$str = '<a href="http://www.baidu.com">百度</a>';
htmlspecialchars($str);
htmlentities($str);
~~~
>**刪除字符串中的標簽**
~~~
strip_tags($str);
~~~
## 9.字符串拆分與合并
>**字符串拆分為數組**
~~~
explode(',',$str);
$str = '21,543:43@6534:432,543';
$res = preg_split('/[^0-9]/',$str);
~~~
>**數組組合為字符串**
~~~
implode(',',$arr);
join(',',$arr);
~~~
## 10.文件寫入與讀取
>**將字符串寫入文件**
~~~
file_put_contents('文件路徑',$a,File_APPEND);
~~~
>**讀取文件的內容**
~~~
file_get_contents('文件路徑');
~~~
## 11.date\time時間函數
>**設置時區**
~~~
date_default_timezone_set('Asia/Shanghai');
~~~
>**當前時間**
~~~
time();
mktime();
strtotime('now');
~~~
>**獲取指定時間的時間戳**
~~~
1991年8月26日9點15分15秒
date('Y年m月d日H時i分s秒',mktime(9,15,15,8,26,1992));
date('Y年m月d日H時i分s秒',strtotime('1991-8-26 9:15:15'));
~~~
>**格式化時間戳**
~~~
date('Y年m月d日',time());
date('Y年m月d日H時i分s秒',time());
~~~
>**獲取微妙**
~~~
microtime(true)->time();
~~~