
PHP
刘看水
这个作者很懒,什么都没留下…
展开
-
PHP去除回车换行
不同系统的换行的实现是不一样的linux 与 unix 中用 \nMAC 用 \rwindow 用 \r\n1. str_replace$str = str_replace(["\r\n", "\r", "\n"], '', $str);2. preg_replace$str = preg_replace('//s*/', '', $str);3. str_repla...原创 2019-02-21 09:25:23 · 295 阅读 · 0 评论 -
PHP 正则preg_match
preg_match—执行匹配正则表达式// 匹配正常的手机号preg_match("/^1[0-9]{10}$/", $mobile);原创 2019-05-22 17:09:06 · 379 阅读 · 0 评论 -
PHP ??
??php7 新提供的表达式// 当 $b 变量已设置并且非 NULL 时, $a = $b;否则 $a = $c;$a = $b ?? $c;// 等价于$a = isset($b) ? $b : $c;原创 2019-05-22 16:36:13 · 128 阅读 · 0 评论 -
时间转换
时间戳 s ms字符串 年:月:日 时:分:秒时间戳 ==> 字符串date('Y-m-d H:i:s', time());原创 2019-05-22 09:07:24 · 248 阅读 · 0 评论 -
PHP file_put_contents
file_put_contents()将一个字符串写入文件和依次调用fopen(),fwrite()以及fclose()功能一样。file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] ) : intIf filename does not ex...原创 2019-05-21 16:54:32 · 273 阅读 · 0 评论 -
PHP file
file()把整个文件读入一个数组中file_get_contents()将整个文件读入一个字符串原创 2019-05-20 17:03:20 · 247 阅读 · 0 评论 -
PHP dirname() 函数
dirname() 函数返回路径中的目录部分。原创 2019-05-20 16:59:49 · 178 阅读 · 0 评论 -
PHP 魔术常量
__FILE__文件的完整路径和文件名。参考:魔术常量原创 2019-05-20 16:52:30 · 123 阅读 · 0 评论 -
PHP static
PHP static(静态)关键字用来定义静态方法和属性,也可用于定义静态变量以及后期静态绑定声明类属性或方法为静态,就可以不实例化类而直接访问静态属性不能通过一个类已实例化的对象来访问(但静态方法可以)。由于静态方法不需要通过对象即可调用,所以伪变量 $this 在静态方法中不可用。静态属性不可以由对象通过 -> 操作符来访问。...原创 2019-05-20 16:05:58 · 952 阅读 · 0 评论 -
MongodbUtil
判断 id 是否为 ObjectIdpublic static function isObjectId($id){ if (is_array($id)) { return false; } if ($id instanceof ObjectID || preg_match('/^[a-f\d]{24}$/i', $id)) { re...原创 2019-05-06 11:08:50 · 768 阅读 · 0 评论 -
php curl post
$url = 'http://www.xxx.com';$headers = [ 'Content-Type: application/json',];$data = [];$data = json_encode($data);$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($c...原创 2019-04-09 16:13:00 · 1632 阅读 · 0 评论 -
PHP array_combine() 函数
通过合并两个数组来创建一个新数组,其中的一个数组元素为键名,另一个数组元素为键值array_combine()原创 2019-04-01 18:22:37 · 260 阅读 · 0 评论 -
utf8_encode
utf8_encode—将 ISO-8859-1 编码的字符串转换为 UTF-8 编码$ts = utf8_encode(date('Y-m-d H:i:s'));原创 2019-04-01 17:30:08 · 1192 阅读 · 0 评论 -
json encode 不转义中文字符
json encode 不转义中文字符$params = json_encode($params, JSON_UNESCAPED_UNICODE);原创 2019-04-01 13:35:10 · 561 阅读 · 0 评论 -
stripos
stripos查找字符串在另一字符串中第一次出现的位置(不区分大小写)<?phpecho stripos("You love php, I love php too!","PHP");?>原创 2019-08-22 10:29:16 · 567 阅读 · 0 评论