- 字符长度
strlen($str) 中文utf8中3个长度 其他字符1个,gb2312中中文2个 mb_strlen($str1,'utf-8');
- 截取,字符串截取,用于英文,长度每个汉字utf8占3字符
substr($str1,0,6); 开始位置0,长度 mb_substr('曾经年少爱追梦一心只想往前飞', 0, 7,'utf-8');
- 查找替换,查找c替换成qqq
str_replace('c','qqq','abcdefg');
- header
header("Content-Type:text/html;charset=UTF-8");
header('Content-type: text/css'); css
header('Content-type: text/javascript'); js
header('Content-type: image/jpeg'); jpg
header('Content-type: application/json'); json
header('Content-type: text/plain'); txt
header('Content-type: text/xml'); xml
header('HTTP/1.1 200 OK'); 200 正常ok
header("HTTP/1.1 404 Not Found");未找到
header("http/1.1 403 Forbidden");无权限
header("http/1.1 301 Moved Permanently");重定向
header('HTTP/1.1 304 Not Modified');没改变
header('Location: http://www.example.org/');
header('Refresh: 10; url=http://www.example.org/');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
跨域
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers:content-type');
header('Content-Type:application/json; charset=utf-8');
serialize 和unserialize 序列化和反序列化
json_encode($arr)和json_decode($json,TRUE)true是返回数组 默认对象
json_encode($arr,JSON_UNESCAPED_UNICODE ) 编码后还是中文
urlencode 和urldecode url编码和解码
mb_convert_encoding('李太白',"utf-8",'auto');自动转换成uft8 iconv('utf-8','gb2312//IGNORE','礼拜是谁');转换成gb2312
strtolower转换小写 strtoupper转换成大写
strtolower('wEws2');
strip_tags($rs0); 去除标签
error_reporting(0);禁止显示错误
error_reporting(E_ALL)显示错误
pathinfo(__FILE__)
Array
(
[dirname] => C:\www
[basename] => Codelobster1.php
[extension] => php
[filename] => Codelobster1
)
- 添加和去除转义符
addslashes("wo \' \"ni是"); 入库添加反斜杠 stripslashes("wo \' \"ni是");
- 转换实体和还原
htmlspecialchars_decode($str) htmlspecialchars("你是",ENT_NOQUOTES,'UTF-8');
- 检测扩展是否存在,curl,gd,openssl
extension_loaded('memcache'); function_exists('curl_init');//检测函数是否存在 class_exists('MyClass')) 检测类是否存在 get_extension_funcs("xml"); 显示所有方法 get_loaded_extensions() 显示所有扩展 get_defined_constants(true)['user']一已定义常量 $arr = get_defined_functions();$arr['user'] 已定义函数
- 如果自动添加转义符没有打开则使用以下
if(!get_magic_quotes_gpc()){ addslashes($var) }
- 解析url
parse_url("http://www.baidu.com/4/1.php?qq=1&d=1#123"); Array ( [scheme] => http [host] => www.baidu.com [path] => /4/1.php [query] => qq=1&d=1 [fragment] => 123 )
- 解析字符串
parse_str("id=23&name=John%20Adams",$arr);输出$arr Array ( [id] => 23 [name] => John Adams )
- 变量数组互换
$arr = array('qq'=>1,'ss'=>5); extract($arr);//转换成变量 $a=1;$b=2; $arr = compact('a','b');
- 获取输入,post可用
$str=file_get_contents('php://input'); 等同$_POST,用于
- $_SERVER
OS系统 [HTTP_HOST] => localhost 域名 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.2; WOW64; Trident/7.0; rv:11.0) like Gecko [SERVER_SOFTWARE] => nginx/1.9.9 [REQUEST_METHOD] => GET [SCRIPT_FILENAME] => C:/www/Codelobster1.php [SERVER_ADDR] => 127.0.0.1 [REMOTE_ADDR] => 127.0.0.1 [REQUEST_URI] => /Codelobster1.php?qq=1
- 生成id
uniqid() 默认13 uniqid('y_',1); 25 没有 y_则是23
- 字符串反序
strrev("abc")
- 去除html标签
strip_tags($str)
- empty和isset
empty判断是否空字符串 空字符串有0 0.0 "" "0" null false [] $var
isset 判断变量是否存在
作者:Yoby 创建时间:2020-07-23 19:23
更新时间:2024-12-05 13:26
更新时间:2024-12-05 13:26