- htmlspecialchars() 和 htmlentites()
1. 將特殊字符轉(zhuǎn)換成html實體 (如'<div></div>'輸出一個div蔑赘,而htmlspeicalchars('<div></div>')會轉(zhuǎn)換成html實體“<div>”再輸出)
2. 將字符串轉(zhuǎn)換成html轉(zhuǎn)義字符 (如'<‘輸出為<蛛淋,而htmlentities('<') 原樣輸出'<')
如果需要反向操作罪治,則使用html_entity_decode()
- fileinfo是php的一個擴展竭翠,php5.3之前需要在php.ini開啟php_fileinfo.dll開啟缚甩,5.3之后默認開啟
1. array_keys()
獲取數(shù)組的鍵值
2. array_values()
獲取數(shù)組的所有值
3. array_merge()
合并兩個或多個數(shù)組
4. array_combine($arr1, $arr2)
將數(shù)組1作為key琼锋,數(shù)組2作為value
5. array_reverse()
顛倒數(shù)組
6. array_push()
末尾追加
7. array_pop()
彈出末尾
8. array_unshift()
頭部追加
9. array_shift()
頭部移除
10. array_slice($arr, $start, $len)
取出部分棵红,不改變原數(shù)組
11. array_splice(&$arr, $start, $len. $replace)
移除部分浩聋,用replace取代
12. array_chunk($arr, $split_len)
數(shù)組分割
13. array_map($arr, user_func)
遍歷數(shù)組观蜗,自定義回調(diào)
14. array_filter($arr, user_func)
自定義回調(diào)篩選
15. each()
遍歷數(shù)組,會移動數(shù)組指針
16. array_search()
數(shù)組查找
17. array_pad($arr, $len, $pad)
數(shù)組填充
18. array_rand()
隨機子集
19. sort()衣洁、asort()墓捻、ksort()吗垮、usort()辫封、rsort()、arsort()素征、krsort()
數(shù)組排序
20. list($a, $b) = ['a', 'b']
數(shù)據(jù)賦值
1. htmlspecialchars
特殊字符轉(zhuǎn)換成html實體
2. htmlentites
將字符串轉(zhuǎn)換成html轉(zhuǎn)義字符
3. addslashes
將字符轉(zhuǎn)中的單引號环凿、雙引號梧兼、反斜線\轉(zhuǎn)義
(addcslashes(str, chars)可以對選定的字符進行轉(zhuǎn)義)
4. strip_tags
去掉字符串中的html和php標簽
5. strtolower
字符串小寫
6. strtoupper
字符串大寫
7. trim
去除兩端空格,\t \r \n
8. str_split($str, $len)
將字符串分割成$len長度的幾個字符串
9. strstr($str, $find)
找到字符串$find第一次出現(xiàn)的位置智听,輸出這個位置右邊的子字符串
10. strlen($str)
獲取字符串的長度(英文)
11. mb_strlen($str, $encoding)
獲取字符串長度根據(jù)編碼
12. strpos($str, $find)
獲取$find第一次出現(xiàn)的位置羽杰,找到返回位置下標渡紫,找不到返回false
stripos--忽略大小寫
凡是加了‘i’的都是忽略大小寫的版本
凡是加了‘r’的都是從右往左的版本
13. substr($str, $start, $len)
獲取子字符串, $len省略為到結(jié)尾,為負數(shù)代表從后往前數(shù)
14. str_pad($str, $len, $pad, $type)
填補字符串到指定長度 $type為STR_PAD_LEFT或者STR_PAD_BOTH或者STR_PAD_RIGHT
15. strcmp($str1, $str2)
字符串比較考赛,大小寫敏感
strcasecmp大小寫不敏感
16. str_shuffle
隨機打亂字符串
17. str_replace($pattern, $replace, $ori_str, $count)
$pattern和$replace可以為數(shù)組
18. str_repeat($str, $times)
字符串重復(fù)
19. explode($split, $str) | implode($split, $arr)
字符串=》數(shù)組
數(shù)組=》字符串
20. md5($str), crypt($str)
字符串加密
21. strrev($str)
反轉(zhuǎn)字符串
1. date(format, [timestamp])
Format:
Y:四位年份
y:兩位年份
m:兩位月份
n:沒有前導(dǎo)0惕澎,月份
M:3位英文月份
d:兩位天數(shù),每月的第幾天
j:沒有前導(dǎo)0颜骤,每月的第幾天唧喉,
D:星期幾,3位英文
N:星期幾复哆,1-7
t:每個月總的天數(shù)
H:兩位小時欣喧,24小時制
h:兩位小時,12小時制
G:沒有前導(dǎo)0的小時梯找,24小時制
g:沒有前導(dǎo)0的小時唆阿,12小時制
2. strtotime()
* strtotime('now')
* strtotime('next Monday')
* strtotime('+1 day')
* strtotime('+1 week')
* strtotime('+1 week +2 days +3 hours +4 minutes +5 seconds')
3. time()
時間戳
4. date_default_timezone_set('PRC')
設(shè)置默認時區(qū)
1. mysqli_connect('host', 'username', 'password', 'dbname')
mysqli數(shù)據(jù)庫連接
2. mysqli_connect_errno()
mysqli連接失敗代碼
3. mysqli_connect_error()
4. mysqli_query()
成功返回True,失敗返回False
5. mysqli_num_rows()
$result = $mysqli->query($sql);
$rows = $result->num_rows();
// or
$result = mysqli_query($sql);
$nums = mysqli_num_rows($result);
6. mysqli_fetch_array()
獲取結(jié)果集锈锤,包含0,1,2..數(shù)字和數(shù)組-列名兩種
mysqli_fetch_assoc()
獲取結(jié)果集驯鳖,使用數(shù)組-列名獲取 $row['id']
mysqli_fetch_row()
獲取結(jié)果集,使用0,1,2.. $row[0], $row[1]
mysqli_fetch_object()
獲取結(jié)果集久免,使用對象方式浅辙,$row->id
7. mysqli_autocommit($conn, False|True)
自動提交,事務(wù)相關(guān)
mysqli_commit()
提交事務(wù)阎姥,需要mysqli_autocommit(false)
mysqli_rollback()
8. mysqli_affected_rows()
$mysqli->affected_rows
影響的行數(shù)
9. mysqli_select_db()
切換數(shù)據(jù)庫
10. statement
```
if ($stmt = $mysqli->prepare('insert into tb(name, age, address) values (?, ?, ?)')) {
$stmt->bindParam("sds", $name, $age, $address);
$name = '小徒徒';
$age = 23;
$adderss = '哈爾濱';
$stmt->execute();
printf("%d rows affected", $stmt->affected_rows);
$stmt->close();
}
if($stmt2 = $mysqli->prepare('select name, age from tb')) {
$stmt2->execute();
$rows = $stmt2->affected_rows();
$stmt2->bind_result($name, $age);
while($stmt2->fetch()) {
printf('%s-%s', $name, $age);
}
$stmt->close();
}
```
1. basename()
去掉路徑信息记舆,獲取文件或者目錄名
2. copy($ori, $des)
文件復(fù)制
3. dirname
獲取文件或目錄所屬的上級目錄
4. disk_free_space()
磁盤剩余空間
disk_total_space()
磁盤總共空間
5. fopen($filename, $mode)
打開文件,獲取句柄呼巴,
$mode為r, r+, w, w+, a, a+, x以讀寫方式創(chuàng)建并打開文件泽腮,如果文件存在,返回false
6. fgetc($handle)
從文件讀取一個字符
7. fgets($handle)
從文件讀取一行
8. file_exists($file)
文件是否存在
9. file_get_contents($path)
將文件內(nèi)容一次性讀入一個字符串衣赶,如果path有特殊字符诊赊,需使用urlencode()
10. file_put_contents($path, $data)
data可以為數(shù)組
11. file($url)
將一個文件讀取到數(shù)組中
12. filectime() 文件創(chuàng)建時間
fileatime() 文件上次訪問時間
filemtime() 文件上次修改時間
13. filesize()
文件大小
14. filetype()
文件類型
15. flock($handle, LOCK_TYPE)
給文件上鎖
LOCK_EX:獨占鎖 w w+, a a+
LOCK_SH:共享鎖 r r+
LOCK_UN:開鎖
16. is_dir()
is_file()
is_link()
17. is_readable()
is_writeable()
18. mkdir()
創(chuàng)建目錄
19. pathinfo()
$pathinfo = pathinfo('/usr/xy/php.ini');
echo $pathinfo['extension']; //ini
echo $pathinfo['basename']; //php.ini
echo $pathinfo['dirname']; // /usr/xy
20. rename()
移動文件
21. rmdir()
刪除文件夾
22. unlink()
刪除文件
23. is_uploaded_file()
為了能使 is_uploaded_file() 函數(shù)正常工作,必段指定類似于 $_FILES['userfile']['tmp_name'] 的變量府瞄,而在從客戶端上傳的文件名 $_FILES['userfile']['name'] 不能正常運作碧磅。
24. move_uploaded_file()
如果是通過POST上傳的文件,則可以移動遵馆,否則返回false
1. opendir()
打開文件夾
$filepath = "/usr/xy";
if(is_dir($filepath)) {
$fp = opendir($filepath);
while(false !== ($file = readdir($fp))) {
echo $file;
}
}
function readdir_recusive($filepath, $prefix = '') {
if(is_dir($filepath)) {
$handle = opendir($filepath);
while(false !== ($file = readdir($handle))) {
if($file != '.' && $file != '..')
{
$filename = mb_convert_encoding($file, 'utf-8', 'gbk');
$fullpath = mb_convert_encoding($filepath.'/'.$file, 'utf-8', 'gbk');
if(is_dir($filepath.'/'.$file)) {
echo '<span style="font-size: 16px; color: #19d;">'.$filename. '</span><br>';
readdir_recusive($filepath.'/'.$file, $prefix.' ');
}
else
{
echo $prefix.'<span style="font-size: 16px; color: #ea4;"><a href="file://'.$fullpath.'" target="__blank">'. $filename . '</a></span><br>';
}
}
}
closedir($handle);
}
}
readdir_recusive(mb_convert_encoding('F://下載', 'gbk', 'utf-8'));