php magic method

常用的php魔术方法,分类汇总Mark在此

1.字符串

截取子字符串
substr(str,start,stop)

判断s2是否是s1的子字符串
strstr(s1,s2)

替换一截
substr_replace(s,replacement,start,length)

获取needle的开始下标索引
strops(str,needle)

去掉转义用的slashes
stripslashes ($str)

2.数组
3.正则

匹配正则表达式
preg_match (pattern,subject, array &matches = null,flags = 0, $offset = 0)

根据正则替换字符串
preg_replace (pattern,replacement, subject,limit = -1, &$count = null)

4.函数

注册当脚本被shutdown时执行的函数,一般用于打扫战场的工作
register_shutdown_function(callback,params)
如果调用的函数是成员函数,callback形如[obj,func]

调用callback函数
call_user_func_array(callback,[param1,...])

存储缓冲区(echo)的输出
ob_start();
$output = ob_get_contents();

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容