@@ -110,7 +110,7 @@ |
||
| 110 | 110 | if ($len <= $split_len) { |
| 111 | 111 | return array($str); |
| 112 | 112 | } |
| 113 | - preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar); |
|
| 113 | + preg_match_all('/.{'.$split_len.'}|[^\x00]{1,'.$split_len.'}$/us', $str, $ar); |
|
| 114 | 114 | |
| 115 | 115 | return $ar[0]; |
| 116 | 116 | } |
@@ -12,43 +12,43 @@ |
||
| 12 | 12 | /** |
| 13 | 13 | * 公共状态码 |
| 14 | 14 | */ |
| 15 | - const COMMON_SUCCESS = 200;//成功 |
|
| 16 | - const COMMON_UNKNOWN = 400;//未知错误 |
|
| 17 | - const COMMON_REQUEST_METHOD = 401;//错误请求(请求方式错误) |
|
| 18 | - const COMMON_HEADER_MISS_PARAM = 402;//缺失头信息 |
|
| 19 | - const COMMON_ACCESS_BARRED = 403;//禁止访问 |
|
| 20 | - const COMMON_NOT_REQUEST = 404;//请求不存在 |
|
| 21 | - const COMMON_TINYMENG_REQUEST_METHOD = 405;//站外链接请求错误 |
|
| 15 | + const COMMON_SUCCESS = 200; //成功 |
|
| 16 | + const COMMON_UNKNOWN = 400; //未知错误 |
|
| 17 | + const COMMON_REQUEST_METHOD = 401; //错误请求(请求方式错误) |
|
| 18 | + const COMMON_HEADER_MISS_PARAM = 402; //缺失头信息 |
|
| 19 | + const COMMON_ACCESS_BARRED = 403; //禁止访问 |
|
| 20 | + const COMMON_NOT_REQUEST = 404; //请求不存在 |
|
| 21 | + const COMMON_TINYMENG_REQUEST_METHOD = 405; //站外链接请求错误 |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * 未授权 420 |
| 25 | 25 | */ |
| 26 | - const COMMON_TOKEN_INVALID = 421;//token无效 |
|
| 27 | - const COMMON_SIGN_ERROR = 422;//签名错误 |
|
| 28 | - const COMMON_NO_ACCESS = 423;//没有权限 |
|
| 26 | + const COMMON_TOKEN_INVALID = 421; //token无效 |
|
| 27 | + const COMMON_SIGN_ERROR = 422; //签名错误 |
|
| 28 | + const COMMON_NO_ACCESS = 423; //没有权限 |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * 数据错误 430 |
| 32 | 32 | */ |
| 33 | - const COMMON_PARAM_INVALID = 431;//参数无效 |
|
| 34 | - const COMMON_PARAM_MISS = 432;//参数缺失 |
|
| 35 | - const COMMON_PARAMS_VERIFY_ERROR = 433;//字段验证失败 |
|
| 36 | - const COMMON_CAPTCHA_INVALID = 434;//验证码错误 |
|
| 37 | - const COMMON_NO_DATA_EXIST = 435;//数据不存在 |
|
| 38 | - const COMMON_DATA_EXIST = 436;//数据已存在 |
|
| 39 | - const COMMON_SAVE_FAILURE = 437;//存储失败 |
|
| 33 | + const COMMON_PARAM_INVALID = 431; //参数无效 |
|
| 34 | + const COMMON_PARAM_MISS = 432; //参数缺失 |
|
| 35 | + const COMMON_PARAMS_VERIFY_ERROR = 433; //字段验证失败 |
|
| 36 | + const COMMON_CAPTCHA_INVALID = 434; //验证码错误 |
|
| 37 | + const COMMON_NO_DATA_EXIST = 435; //数据不存在 |
|
| 38 | + const COMMON_DATA_EXIST = 436; //数据已存在 |
|
| 39 | + const COMMON_SAVE_FAILURE = 437; //存储失败 |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * 用户错误码 440 |
| 43 | 43 | */ |
| 44 | - const COMMON_NOT_ENTERED_PASSWORD = 440;//未输入密码 |
|
| 45 | - const COMMON_PASSWORD_INVALID = 441;//密码错误 |
|
| 44 | + const COMMON_NOT_ENTERED_PASSWORD = 440; //未输入密码 |
|
| 45 | + const COMMON_PASSWORD_INVALID = 441; //密码错误 |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * 系统状态码 300000 |
| 49 | 49 | */ |
| 50 | - const USER_STOP_USE = 300105;//用户停止使用 |
|
| 51 | - const USER_SYSTEM_UPDATE = 300109;//系统升级 |
|
| 50 | + const USER_STOP_USE = 300105; //用户停止使用 |
|
| 51 | + const USER_SYSTEM_UPDATE = 300109; //系统升级 |
|
| 52 | 52 | |
| 53 | 53 | public static $status_code = [ |
| 54 | 54 | //公共错误码 |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Description: Tool.php. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -class Encryption{ |
|
| 11 | +class Encryption { |
|
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @return bool|string |
| 23 | 23 | */ |
| 24 | 24 | static public function authcode($string, $operation = 'decode', $key = 'tinymeng', $expiry = 0) { |
| 25 | - $ckey_length = 4; // 随机密钥长度 取值 0-32; |
|
| 25 | + $ckey_length = 4; // 随机密钥长度 取值 0-32; |
|
| 26 | 26 | // 加入随机密钥,可以令密文无任何规律,即便是原文和密钥完全相同,加密结果也会每次不同,增大破解难度。 |
| 27 | 27 | // 取值越大,密文变动规律越大,密文变化 = 16 的 $ckey_length 次方 |
| 28 | 28 | // 当此值为 0 时,则不产生随机密钥 |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | $key = md5($key); |
| 31 | 31 | $keya = md5(substr($key, 0, 16)); |
| 32 | 32 | $keyb = md5(substr($key, 16, 16)); |
| 33 | - $keyc = $ckey_length ? ($operation == 'decode' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; |
|
| 33 | + $keyc = $ckey_length ? ($operation == 'decode' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : ''; |
|
| 34 | 34 | |
| 35 | 35 | $cryptkey = $keya.md5($keya.$keyc); |
| 36 | 36 | $key_length = strlen($cryptkey); |
| 37 | 37 | |
| 38 | - if($operation == 'decode'){ |
|
| 38 | + if ($operation == 'decode') { |
|
| 39 | 39 | $string = base64_decode(substr($string, $ckey_length)); |
| 40 | - }else{ |
|
| 40 | + } else { |
|
| 41 | 41 | $a = $expiry ? $expiry + time() : 0; |
| 42 | 42 | $string = sprintf('%010d', $a).substr(md5($string.$keyb), 0, 16).$string; |
| 43 | 43 | } |
@@ -47,27 +47,27 @@ discard block |
||
| 47 | 47 | $box = range(0, 255); |
| 48 | 48 | |
| 49 | 49 | $rndkey = array(); |
| 50 | - for($i = 0; $i <= 255; $i++) { |
|
| 50 | + for ($i = 0; $i <= 255; $i++) { |
|
| 51 | 51 | $rndkey[$i] = ord($cryptkey[$i % $key_length]); |
| 52 | 52 | } |
| 53 | - for($j = $i = 0; $i < 256; $i++) { |
|
| 53 | + for ($j = $i = 0; $i < 256; $i++) { |
|
| 54 | 54 | $j = ($j + $box[$i] + $rndkey[$i]) % 256; |
| 55 | 55 | $tmp = $box[$i]; |
| 56 | 56 | $box[$i] = $box[$j]; |
| 57 | 57 | $box[$j] = $tmp; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - for($a = $j = $i = 0; $i < $string_length; $i++) { |
|
| 60 | + for ($a = $j = $i = 0; $i < $string_length; $i++) { |
|
| 61 | 61 | $a = ($a + 1) % 256; |
| 62 | 62 | $j = ($j + $box[$a]) % 256; |
| 63 | 63 | $tmp = $box[$a]; |
| 64 | 64 | $box[$a] = $box[$j]; |
| 65 | 65 | $box[$j] = $tmp; |
| 66 | - $result .= chr( ord($string[$i]) ^ ( $box[($box[$a] + $box[$j]) % 256])); |
|
| 66 | + $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if($operation == 'decode') { |
|
| 70 | - if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { |
|
| 69 | + if ($operation == 'decode') { |
|
| 70 | + if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { |
|
| 71 | 71 | return substr($result, 26); |
| 72 | 72 | } else { |
| 73 | 73 | return ''; |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | |
| 38 | 38 | if($operation == 'decode'){ |
| 39 | 39 | $string = base64_decode(substr($string, $ckey_length)); |
| 40 | - }else{ |
|
| 40 | + } else{ |
|
| 41 | 41 | $a = $expiry ? $expiry + time() : 0; |
| 42 | 42 | $string = sprintf('%010d', $a).substr(md5($string.$keyb), 0, 16).$string; |
| 43 | 43 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | { |
| 219 | 219 | $date = $this->makeDate("{$year}-{$month}-{$day}"); |
| 220 | 220 | $lunar = $this->solar2lunar($year, $month, $day, $hour); |
| 221 | - $week = abs((int)$date->format('w')); // 0 ~ 6 修正 星期七 为 星期日 |
|
| 221 | + $week = abs((int) $date->format('w')); // 0 ~ 6 修正 星期七 为 星期日 |
|
| 222 | 222 | |
| 223 | 223 | return array_merge( |
| 224 | 224 | $lunar, |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | if ($no < 1 || $no > 24) { |
| 435 | 435 | return -1; |
| 436 | 436 | } |
| 437 | - $solarTermsOfYear = array_map('hexdec', (array)str_split($this->solarTerms[$year - 1900], 5)); |
|
| 437 | + $solarTermsOfYear = array_map('hexdec', (array) str_split($this->solarTerms[$year - 1900], 5)); |
|
| 438 | 438 | $positions = [ |
| 439 | 439 | 0 => [0, 1], |
| 440 | 440 | 1 => [1, 2], |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | throw new InvalidArgumentException("不支持的日期:{$year}-{$month}-{$day}"); |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | - $offset = (int)$this->dateDiff($date, '1900-01-31')->days; |
|
| 601 | + $offset = (int) $this->dateDiff($date, '1900-01-31')->days; |
|
| 602 | 602 | |
| 603 | 603 | for ($i = 1900; $i < 2101 && $offset > 0; ++$i) { |
| 604 | 604 | $daysOfYear = $this->daysOfYear($i); |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | $date = $this->makeDate("{$solar['solar_year']}-{$solar['solar_month']}-{$solar['solar_day']}"); |
| 1118 | 1118 | $date->modify($value.' day'); |
| 1119 | 1119 | |
| 1120 | - return $this->solar2lunar((int)$date->format('Y'), (int)$date->format('m'), (int)$date->format('d')); |
|
| 1120 | + return $this->solar2lunar((int) $date->format('Y'), (int) $date->format('m'), (int) $date->format('d')); |
|
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | /** |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | class RsaTool |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - private $rsaPath = './';//公钥证书路径 |
|
| 13 | + private $rsaPath = './'; //公钥证书路径 |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Author: JiaMeng <[email protected]> |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | // 生成私钥 |
| 63 | 63 | $rsa = openssl_pkey_new($config); |
| 64 | 64 | openssl_pkey_export($rsa, $privKey, $this->privkeypass, $config); |
| 65 | - file_put_contents($this->rsaPath . DIRECTORY_SEPARATOR . 'priv.key', $privKey); |
|
| 65 | + file_put_contents($this->rsaPath.DIRECTORY_SEPARATOR.'priv.key', $privKey); |
|
| 66 | 66 | // 生成公钥 |
| 67 | 67 | $rsaPri = openssl_pkey_get_details($rsa); |
| 68 | 68 | $pubKey = $rsaPri['key']; |
| 69 | - file_put_contents($this->rsaPath . DIRECTORY_SEPARATOR . 'pub.key', $pubKey); |
|
| 69 | + file_put_contents($this->rsaPath.DIRECTORY_SEPARATOR.'pub.key', $pubKey); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function setupPrivKey() |
| 77 | 77 | { |
| 78 | - $file = $this->rsaPath . DIRECTORY_SEPARATOR . 'priv.key'; |
|
| 78 | + $file = $this->rsaPath.DIRECTORY_SEPARATOR.'priv.key'; |
|
| 79 | 79 | $privKey = file_get_contents($file); |
| 80 | 80 | $this->_privKey = openssl_pkey_get_private($privKey, $this->privkeypass); |
| 81 | 81 | return true; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function setupPubKey() |
| 89 | 89 | { |
| 90 | - $file = $this->rsaPath . DIRECTORY_SEPARATOR . 'pub.key'; |
|
| 90 | + $file = $this->rsaPath.DIRECTORY_SEPARATOR.'pub.key'; |
|
| 91 | 91 | $pubKey = file_get_contents($file); |
| 92 | 92 | $this->_pubKey = openssl_pkey_get_public($pubKey); |
| 93 | 93 | return true; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | if($type == 'asc'){ |
| 25 | 25 | asort($keysValue); |
| 26 | - }else{ |
|
| 26 | + } else{ |
|
| 27 | 27 | arsort($keysValue); |
| 28 | 28 | } |
| 29 | 29 | reset($keysValue); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | if(is_array($val)){ |
| 89 | 89 | if(empty($val)){ |
| 90 | 90 | settype($val,'object'); |
| 91 | - }else{ |
|
| 91 | + } else{ |
|
| 92 | 92 | self::nullArrayToObject($val); |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Description: Tool.php. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -class ArrayTool{ |
|
| 11 | +class ArrayTool { |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @param $arr |
@@ -16,20 +16,20 @@ discard block |
||
| 16 | 16 | * @param $type |
| 17 | 17 | * @return array |
| 18 | 18 | */ |
| 19 | - static public function arraySort($arr,$keys,$type='asc'){ |
|
| 19 | + static public function arraySort($arr, $keys, $type = 'asc') { |
|
| 20 | 20 | $keysValue = $newArray = array(); |
| 21 | - foreach ($arr as $k=>$v){ |
|
| 22 | - if(isset($v[$keys])){ |
|
| 21 | + foreach ($arr as $k=>$v) { |
|
| 22 | + if (isset($v[$keys])) { |
|
| 23 | 23 | $keysValue[$k] = $v[$keys]; |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | - if($type == 'asc'){ |
|
| 26 | + if ($type == 'asc') { |
|
| 27 | 27 | asort($keysValue); |
| 28 | - }else{ |
|
| 28 | + } else { |
|
| 29 | 29 | arsort($keysValue); |
| 30 | 30 | } |
| 31 | 31 | reset($keysValue); |
| 32 | - foreach ($keysValue as $k=>$v){ |
|
| 32 | + foreach ($keysValue as $k=>$v) { |
|
| 33 | 33 | $newArray[$k] = $arr[$k]; |
| 34 | 34 | } |
| 35 | 35 | return array_values($newArray); |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * @param string $childrenName child |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | - public static function getTreeStructureRecursion(array $list,string $filed='id',string $parentFiled='pid',int $parentId=0,string $childrenName = 'child') |
|
| 49 | + public static function getTreeStructureRecursion(array $list, string $filed = 'id', string $parentFiled = 'pid', int $parentId = 0, string $childrenName = 'child') |
|
| 50 | 50 | { |
| 51 | 51 | $result = array(); |
| 52 | - if(!empty($list)){ |
|
| 53 | - foreach($list as $val){ |
|
| 54 | - if($val[$parentFiled] == $parentId){ |
|
| 55 | - $val[$childrenName] = self::getTreeStructureRecursion($list,$filed,$parentFiled,$val[$filed]); |
|
| 56 | - if(empty($val[$childrenName])){ |
|
| 52 | + if (!empty($list)) { |
|
| 53 | + foreach ($list as $val) { |
|
| 54 | + if ($val[$parentFiled] == $parentId) { |
|
| 55 | + $val[$childrenName] = self::getTreeStructureRecursion($list, $filed, $parentFiled, $val[$filed]); |
|
| 56 | + if (empty($val[$childrenName])) { |
|
| 57 | 57 | unset($val[$childrenName]); |
| 58 | 58 | } |
| 59 | 59 | $result[] = $val; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param string $childrenName child |
| 74 | 74 | * @return array |
| 75 | 75 | */ |
| 76 | - public static function getTreeStructure(array $list,string $filed = 'id', string $parentFiled = 'pid', string $childrenName = 'child') |
|
| 76 | + public static function getTreeStructure(array $list, string $filed = 'id', string $parentFiled = 'pid', string $childrenName = 'child') |
|
| 77 | 77 | { |
| 78 | 78 | $result = array(); |
| 79 | 79 | foreach ($list as $value) { |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | * @param $obj |
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | - public static function objectToArray($obj){ |
|
| 101 | - if(!is_object($obj) && !is_array($obj)) { |
|
| 100 | + public static function objectToArray($obj) { |
|
| 101 | + if (!is_object($obj) && !is_array($obj)) { |
|
| 102 | 102 | return $obj; |
| 103 | 103 | } |
| 104 | 104 | $arr = array(); |
| 105 | - foreach($obj as $k => $v){ |
|
| 105 | + foreach ($obj as $k => $v) { |
|
| 106 | 106 | $arr[$k] = self::objectToArray($v); |
| 107 | 107 | } |
| 108 | 108 | return $arr; |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | * @Author: TinyMeng <[email protected]> |
| 115 | 115 | * @param $data |
| 116 | 116 | */ |
| 117 | - public static function nullArrayToObject(&$data){ |
|
| 118 | - foreach ($data as $key=>&$val){ |
|
| 119 | - if(is_array($val)){ |
|
| 120 | - if(empty($val)){ |
|
| 121 | - settype($val,'object'); |
|
| 122 | - }else{ |
|
| 117 | + public static function nullArrayToObject(&$data) { |
|
| 118 | + foreach ($data as $key=>&$val) { |
|
| 119 | + if (is_array($val)) { |
|
| 120 | + if (empty($val)) { |
|
| 121 | + settype($val, 'object'); |
|
| 122 | + } else { |
|
| 123 | 123 | self::nullArrayToObject($val); |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | * 文件操作类 |
| 5 | 5 | * logFilePath: /storage/tinymeng/log/ |
| 6 | 6 | */ |
| 7 | -define('logFilePath',dirname(dirname(dirname(dirname(__DIR__)))).DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'tinymeng'.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR); |
|
| 8 | -class FileTool{ |
|
| 7 | +define('logFilePath', dirname(dirname(dirname(dirname(__DIR__)))).DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'tinymeng'.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR); |
|
| 8 | +class FileTool { |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Name: writeLog |
@@ -16,26 +16,26 @@ discard block |
||
| 16 | 16 | * @param \Exception|null $exception |
| 17 | 17 | * @return bool |
| 18 | 18 | */ |
| 19 | - static public function writeLog($message, $file_name='error',bool $echo = false,\Exception $exception = null){ |
|
| 20 | - if(!is_string($message)){ |
|
| 19 | + static public function writeLog($message, $file_name = 'error', bool $echo = false, \Exception $exception = null) { |
|
| 20 | + if (!is_string($message)) { |
|
| 21 | 21 | $message = json_encode($message); |
| 22 | 22 | } |
| 23 | 23 | $message = date('Y-m-d H:i:s').' : '.$message.PHP_EOL; |
| 24 | - if($exception && $exception instanceof \Exception){ |
|
| 24 | + if ($exception && $exception instanceof \Exception) { |
|
| 25 | 25 | $message .= ' File: '.$exception->getFile().' ,Line: '.$exception->getLine().' ,Message: '.$exception->getMessage(); |
| 26 | 26 | } |
| 27 | - if($echo){ |
|
| 27 | + if ($echo) { |
|
| 28 | 28 | echo $message; |
| 29 | 29 | } |
| 30 | 30 | $path = logFilePath; |
| 31 | 31 | if (!is_dir($path)) { |
| 32 | - if(!mkdir($path, 0755, true)){ |
|
| 32 | + if (!mkdir($path, 0755, true)) { |
|
| 33 | 33 | die('创建缓存文件夹"'.$path.'"失败!'); |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $file_name = $path.$file_name; |
| 38 | - self::filePutContents($file_name."-".date('Ymd',time()).".log",$message,true); |
|
| 38 | + self::filePutContents($file_name."-".date('Ymd', time()).".log", $message, true); |
|
| 39 | 39 | return true; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | * file_put_contents和fopen,fwrite,fclose三个组合的区别 |
| 49 | 49 | * http://blog.majiameng.com/article/2724.html |
| 50 | 50 | */ |
| 51 | - static public function filePutContents(string $file_name,string $content,bool $file_append = false){ |
|
| 52 | - if(strrpos($file_name,DIRECTORY_SEPARATOR)){ |
|
| 51 | + static public function filePutContents(string $file_name, string $content, bool $file_append = false) { |
|
| 52 | + if (strrpos($file_name, DIRECTORY_SEPARATOR)) { |
|
| 53 | 53 | //获取文件夹路径 |
| 54 | - $dir_name = substr($file_name,0,strrpos($file_name,DIRECTORY_SEPARATOR)); |
|
| 54 | + $dir_name = substr($file_name, 0, strrpos($file_name, DIRECTORY_SEPARATOR)); |
|
| 55 | 55 | //创建文件夹 |
| 56 | 56 | self::mkdir($dir_name); |
| 57 | 57 | } |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | self::chmod($file_name); |
| 61 | 61 | |
| 62 | 62 | //内容写入文件 |
| 63 | - if($file_append === false){ |
|
| 64 | - file_put_contents($file_name,$content); |
|
| 65 | - }else{ |
|
| 66 | - file_put_contents($file_name,$content,FILE_APPEND); |
|
| 63 | + if ($file_append === false) { |
|
| 64 | + file_put_contents($file_name, $content); |
|
| 65 | + } else { |
|
| 66 | + file_put_contents($file_name, $content, FILE_APPEND); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | * file_put_contents和fopen,fwrite,fclose三个组合的区别 |
| 77 | 77 | * http://blog.majiameng.com/article/2724.html |
| 78 | 78 | */ |
| 79 | - static public function fWrite(string $file_name,string $content,bool $file_append = false){ |
|
| 80 | - if(strrpos($file_name,DIRECTORY_SEPARATOR)){ |
|
| 79 | + static public function fWrite(string $file_name, string $content, bool $file_append = false) { |
|
| 80 | + if (strrpos($file_name, DIRECTORY_SEPARATOR)) { |
|
| 81 | 81 | //获取文件夹路径 |
| 82 | - $dir_name = substr($file_name,0,strrpos($file_name,DIRECTORY_SEPARATOR)); |
|
| 82 | + $dir_name = substr($file_name, 0, strrpos($file_name, DIRECTORY_SEPARATOR)); |
|
| 83 | 83 | //创建文件夹 |
| 84 | 84 | self::mkdir($dir_name); |
| 85 | 85 | } |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | self::chmod($file_name); |
| 89 | 89 | |
| 90 | 90 | //内容写入文件 |
| 91 | - if($file_append === false){ |
|
| 91 | + if ($file_append === false) { |
|
| 92 | 92 | $handle = fopen($file_name, 'w'); |
| 93 | 93 | fwrite($handle, $content); |
| 94 | 94 | fclose($handle); |
| 95 | - }else{ |
|
| 95 | + } else { |
|
| 96 | 96 | $handle = fopen($file_name, 'a'); |
| 97 | 97 | fwrite($handle, $content); |
| 98 | 98 | fclose($handle); |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * @param $dir_name |
| 106 | 106 | * @return bool |
| 107 | 107 | */ |
| 108 | - static public function mkdir(string $dir_name){ |
|
| 108 | + static public function mkdir(string $dir_name) { |
|
| 109 | 109 | if (!is_dir($dir_name)) { |
| 110 | - if(!mkdir($dir_name, 0755, true)){ |
|
| 110 | + if (!mkdir($dir_name, 0755, true)) { |
|
| 111 | 111 | die('创建缓存文件夹"'.$dir_name.'"失败!'); |
| 112 | 112 | } |
| 113 | 113 | //添加文件权限 |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @return bool |
| 124 | 124 | */ |
| 125 | 125 | static public function delDir(string $dir) { |
| 126 | - if(!file_exists($dir)){//文件不存在 |
|
| 126 | + if (!file_exists($dir)) {//文件不存在 |
|
| 127 | 127 | return true; |
| 128 | 128 | } |
| 129 | 129 | if (!is_dir($dir)) { |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | //先删除目录下的文件 |
| 135 | 135 | $dh = opendir($dir); |
| 136 | 136 | while ($file = readdir($dh)) { |
| 137 | - if($file != "." && $file!="..") { |
|
| 137 | + if ($file != "." && $file != "..") { |
|
| 138 | 138 | $full_path = $dir."/".$file; |
| 139 | - if(!is_dir($full_path)) { |
|
| 139 | + if (!is_dir($full_path)) { |
|
| 140 | 140 | unlink($full_path); |
| 141 | 141 | } else { |
| 142 | 142 | self::delDir($full_path); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | closedir($dh); |
| 147 | 147 | |
| 148 | 148 | //删除当前文件夹: |
| 149 | - if(rmdir($dir)) { |
|
| 149 | + if (rmdir($dir)) { |
|
| 150 | 150 | return true; |
| 151 | 151 | } else { |
| 152 | 152 | return false; |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | * @param $file_name |
| 160 | 160 | * @param int $mode |
| 161 | 161 | */ |
| 162 | - static public function chmod($file_name,$mode = 0755){ |
|
| 163 | - if (file_exists($file_name)){ |
|
| 164 | - @chmod($file_name,$mode); |
|
| 162 | + static public function chmod($file_name, $mode = 0755) { |
|
| 163 | + if (file_exists($file_name)) { |
|
| 164 | + @chmod($file_name, $mode); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | * dirname()可以的当前文件目录 |
| 173 | 173 | * @return array |
| 174 | 174 | */ |
| 175 | - static public function scanDir($path){ |
|
| 175 | + static public function scanDir($path) { |
|
| 176 | 176 | $filename = scandir($path); |
| 177 | 177 | $result = array(); |
| 178 | - foreach($filename as $k=>$v){ |
|
| 178 | + foreach ($filename as $k=>$v) { |
|
| 179 | 179 | // 跳过两个特殊目录 continue跳出循环 |
| 180 | - if($v=="." || $v==".."){continue;} |
|
| 180 | + if ($v == "." || $v == "..") {continue; } |
|
| 181 | 181 | $result[] = $v; |
| 182 | 182 | } |
| 183 | 183 | return $result; |
@@ -193,21 +193,21 @@ discard block |
||
| 193 | 193 | static public function move(string $file, string $new_file): bool |
| 194 | 194 | { |
| 195 | 195 | //文件是否存在 |
| 196 | - if(!file_exists($file)){ |
|
| 196 | + if (!file_exists($file)) { |
|
| 197 | 197 | return false; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | //新文件目录 |
| 201 | - if(strrpos($new_file,DIRECTORY_SEPARATOR)){ |
|
| 201 | + if (strrpos($new_file, DIRECTORY_SEPARATOR)) { |
|
| 202 | 202 | //获取文件夹路径 |
| 203 | - $dir_name = substr($new_file,0,strrpos($new_file,DIRECTORY_SEPARATOR)); |
|
| 203 | + $dir_name = substr($new_file, 0, strrpos($new_file, DIRECTORY_SEPARATOR)); |
|
| 204 | 204 | //创建文件夹 |
| 205 | 205 | self::mkdir($dir_name); |
| 206 | 206 | //添加文件权限 |
| 207 | 207 | self::chmod($dir_name); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - copy($file,$new_file); //拷贝到新目录 |
|
| 210 | + copy($file, $new_file); //拷贝到新目录 |
|
| 211 | 211 | unlink($file); //删除旧目录下的文件 |
| 212 | 212 | |
| 213 | 213 | return true; |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | //内容写入文件 |
| 63 | 63 | if($file_append === false){ |
| 64 | 64 | file_put_contents($file_name,$content); |
| 65 | - }else{ |
|
| 65 | + } else{ |
|
| 66 | 66 | file_put_contents($file_name,$content,FILE_APPEND); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $handle = fopen($file_name, 'w'); |
| 93 | 93 | fwrite($handle, $content); |
| 94 | 94 | fclose($handle); |
| 95 | - }else{ |
|
| 95 | + } else{ |
|
| 96 | 96 | $handle = fopen($file_name, 'a'); |
| 97 | 97 | fwrite($handle, $content); |
| 98 | 98 | fclose($handle); |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | if(empty($time)){ |
| 76 | 76 | list($msec, $sec) = explode(' ', microtime()); |
| 77 | 77 | $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
| 78 | - }elseif(is_numeric($time) && strlen((string)$time)==10){ |
|
| 78 | + } elseif(is_numeric($time) && strlen((string)$time)==10){ |
|
| 79 | 79 | $millisecond = (string)$time."000"; |
| 80 | - }else{ |
|
| 80 | + } else{ |
|
| 81 | 81 | $millisecond = strtotime($time)."000"; |
| 82 | 82 | } |
| 83 | 83 | return (int)$millisecond; |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | foreach ($string as $key => $val) { |
| 163 | 163 | $_key = self::autoCharset($key, $from, $to); |
| 164 | 164 | $string[$_key] = self::autoCharset($val, $from, $to); |
| 165 | - if ($key != $_key) |
|
| 166 | - unset($string[$key]); |
|
| 165 | + if ($key != $_key) { |
|
| 166 | + unset($string[$key]); |
|
| 167 | + } |
|
| 167 | 168 | } |
| 168 | 169 | return $string; |
| 169 | - } |
|
| 170 | - else { |
|
| 170 | + } else { |
|
| 171 | 171 | return $string; |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | public static function getTime($date,$is_timestamp=false):string { |
| 206 | 206 | if($is_timestamp === true){ |
| 207 | 207 | $time = $date; |
| 208 | - }else{ |
|
| 208 | + } else{ |
|
| 209 | 209 | $time = strtotime($date);//时间转换为时间戳 |
| 210 | 210 | } |
| 211 | 211 | |
@@ -80,22 +80,22 @@ discard block |
||
| 80 | 80 | $str = ''; |
| 81 | 81 | switch ($type) { |
| 82 | 82 | case 0: |
| 83 | - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars; |
|
| 83 | + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars; |
|
| 84 | 84 | break; |
| 85 | 85 | case 1: |
| 86 | 86 | $chars = str_repeat('0123456789', 3); |
| 87 | 87 | break; |
| 88 | 88 | case 2: |
| 89 | - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars; |
|
| 89 | + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars; |
|
| 90 | 90 | break; |
| 91 | 91 | case 3: |
| 92 | - $chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars; |
|
| 92 | + $chars = 'abcdefghijklmnopqrstuvwxyz'.$addChars; |
|
| 93 | 93 | break; |
| 94 | 94 | case 4: |
| 95 | - $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书" . $addChars; |
|
| 95 | + $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书".$addChars; |
|
| 96 | 96 | break; |
| 97 | 97 | default: |
| 98 | - $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars; |
|
| 98 | + $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars; |
|
| 99 | 99 | break; |
| 100 | 100 | } |
| 101 | 101 | if ($length > 10) { |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | if (!ctype_lower($value)) { |
| 177 | 177 | $value = preg_replace('/\s+/u', '', ucwords($value)); |
| 178 | 178 | |
| 179 | - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); |
|
| 179 | + $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | return static::$snakeCache[$key][$delimiter] = $value; |
@@ -259,16 +259,16 @@ discard block |
||
| 259 | 259 | static public function createChannelId($namespace = ''):string { |
| 260 | 260 | static $guid = ''; |
| 261 | 261 | $uid = uniqid("", true); |
| 262 | - $data = $namespace. md5(time() . mt_rand(1,1000000)).uniqid(); |
|
| 263 | - $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data))); |
|
| 264 | - $guid = substr($hash, 0, 8) . |
|
| 265 | - '-' . |
|
| 266 | - substr($hash, 8, 4) . |
|
| 267 | - '-' . |
|
| 268 | - substr($hash, 12, 4) . |
|
| 269 | - '-' . |
|
| 270 | - substr($hash, 16, 4) . |
|
| 271 | - '-' . |
|
| 262 | + $data = $namespace.md5(time().mt_rand(1, 1000000)).uniqid(); |
|
| 263 | + $hash = strtoupper(hash('ripemd128', $uid.$guid.md5($data))); |
|
| 264 | + $guid = substr($hash, 0, 8). |
|
| 265 | + '-'. |
|
| 266 | + substr($hash, 8, 4). |
|
| 267 | + '-'. |
|
| 268 | + substr($hash, 12, 4). |
|
| 269 | + '-'. |
|
| 270 | + substr($hash, 16, 4). |
|
| 271 | + '-'. |
|
| 272 | 272 | substr($hash, 20, 12); |
| 273 | 273 | return $guid; |
| 274 | 274 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | 283 | static public function md5Bit16($str):string { |
| 284 | - return strtoupper(substr(md5($str),8,16)); |
|
| 284 | + return strtoupper(substr(md5($str), 8, 16)); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -291,15 +291,15 @@ discard block |
||
| 291 | 291 | * @return int |
| 292 | 292 | */ |
| 293 | 293 | static public function millisecond($time = null) :int{ |
| 294 | - if(empty($time)){ |
|
| 294 | + if (empty($time)) { |
|
| 295 | 295 | list($msec, $sec) = explode(' ', microtime()); |
| 296 | - $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|
| 297 | - }elseif(is_numeric($time) && strlen((string)$time)==10){ |
|
| 298 | - $millisecond = (string)$time."000"; |
|
| 299 | - }else{ |
|
| 296 | + $millisecond = (int) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|
| 297 | + }elseif (is_numeric($time) && strlen((string) $time) == 10) { |
|
| 298 | + $millisecond = (string) $time."000"; |
|
| 299 | + } else { |
|
| 300 | 300 | $millisecond = strtotime($time)."000"; |
| 301 | 301 | } |
| 302 | - return (int)$millisecond; |
|
| 302 | + return (int) $millisecond; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | * @param string $string |
| 309 | 309 | * @return bool |
| 310 | 310 | */ |
| 311 | - public static function isContainChinese($string=''):bool { |
|
| 311 | + public static function isContainChinese($string = ''):bool { |
|
| 312 | 312 | $result = preg_match('/[\x{4e00}-\x{9fa5}]/u', $string); |
| 313 | 313 | return $result == 0 ? false : true; |
| 314 | 314 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @param string $string |
| 320 | 320 | * @return bool |
| 321 | 321 | */ |
| 322 | - public static function isAllChinese($string=''):bool { |
|
| 322 | + public static function isAllChinese($string = ''):bool { |
|
| 323 | 323 | $result = preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $string); |
| 324 | 324 | return $result == 0 ? false : true; |
| 325 | 325 | } |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @param string $string |
| 332 | 332 | * @return bool |
| 333 | 333 | */ |
| 334 | - public static function isMobile($string=''):bool { |
|
| 334 | + public static function isMobile($string = ''):bool { |
|
| 335 | 335 | if (!preg_match("/(^1[3|4|5|7|8][0-9]{9}$)/", $string)) { |
| 336 | 336 | return false; |
| 337 | 337 | } |
@@ -346,9 +346,9 @@ discard block |
||
| 346 | 346 | * @param int $double 小数点保留位数 默认3位 |
| 347 | 347 | * @return string |
| 348 | 348 | */ |
| 349 | - public static function sctonum($num, $double = 3){ |
|
| 350 | - if(false !== stripos($num, "e")){ |
|
| 351 | - $a = explode("e",strtolower($num)); |
|
| 349 | + public static function sctonum($num, $double = 3) { |
|
| 350 | + if (false !== stripos($num, "e")) { |
|
| 351 | + $a = explode("e", strtolower($num)); |
|
| 352 | 352 | return bcmul($a[0], bcpow(10, $a[1], $double), $double); |
| 353 | 353 | } |
| 354 | 354 | return $num; |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @param string $to |
| 363 | 363 | * @return array|false|string|string[]|null |
| 364 | 364 | */ |
| 365 | - public static function autoCharset($string, $from='gbk', $to='utf-8') { |
|
| 365 | + public static function autoCharset($string, $from = 'gbk', $to = 'utf-8') { |
|
| 366 | 366 | $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; |
| 367 | 367 | $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; |
| 368 | 368 | if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) { |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @param $html |
| 399 | 399 | * @return string |
| 400 | 400 | */ |
| 401 | - public static function filterATag($html=''):string { |
|
| 401 | + public static function filterATag($html = ''):string { |
|
| 402 | 402 | return preg_replace("#<a[^>]*>(.*?)</a>#is", "$1", $html); |
| 403 | 403 | } |
| 404 | 404 | |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | * @param $html |
| 410 | 410 | * @return string |
| 411 | 411 | */ |
| 412 | - public static function deleteATag($html=''):string { |
|
| 412 | + public static function deleteATag($html = ''):string { |
|
| 413 | 413 | return preg_replace("#<a[^>]*>(.*?)</a>#is", "", $html); |
| 414 | 414 | } |
| 415 | 415 | |
@@ -421,36 +421,36 @@ discard block |
||
| 421 | 421 | * @param bool $is_timestamp 是否是时间戳 |
| 422 | 422 | * @return string |
| 423 | 423 | */ |
| 424 | - public static function getTime($date,$is_timestamp=false):string { |
|
| 425 | - if($is_timestamp === true){ |
|
| 424 | + public static function getTime($date, $is_timestamp = false):string { |
|
| 425 | + if ($is_timestamp === true) { |
|
| 426 | 426 | $time = $date; |
| 427 | - }else{ |
|
| 428 | - $time = strtotime($date);//时间转换为时间戳 |
|
| 427 | + } else { |
|
| 428 | + $time = strtotime($date); //时间转换为时间戳 |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - if($time >= time()){ |
|
| 431 | + if ($time >= time()) { |
|
| 432 | 432 | return '刚刚'; |
| 433 | 433 | } |
| 434 | 434 | $seconds = time() - $time; |
| 435 | - if($seconds <= 60){ |
|
| 435 | + if ($seconds <= 60) { |
|
| 436 | 436 | return '刚刚'; |
| 437 | 437 | } |
| 438 | 438 | $minutes = intval($seconds / 60); |
| 439 | - if($minutes <= 60){ |
|
| 439 | + if ($minutes <= 60) { |
|
| 440 | 440 | return $minutes.'分钟前'; |
| 441 | 441 | } |
| 442 | 442 | $hours = intval($minutes / 60); |
| 443 | - if($hours <= 24){ |
|
| 443 | + if ($hours <= 24) { |
|
| 444 | 444 | return $hours.'小时前'; |
| 445 | 445 | } |
| 446 | 446 | $days = intval($hours / 24); |
| 447 | - if($days <= 3){ |
|
| 447 | + if ($days <= 3) { |
|
| 448 | 448 | return $days.'天前'; |
| 449 | 449 | } |
| 450 | - if($days <= 365){ |
|
| 451 | - return date('m-d',/** @scrutinizer ignore-type */ $time); |
|
| 450 | + if ($days <= 365) { |
|
| 451 | + return date('m-d', /** @scrutinizer ignore-type */ $time); |
|
| 452 | 452 | } |
| 453 | - return date('Y-m-d',$time); |
|
| 453 | + return date('Y-m-d', $time); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -464,11 +464,11 @@ discard block |
||
| 464 | 464 | $compress = ''; |
| 465 | 465 | foreach ($chunks as $c) { |
| 466 | 466 | if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') { |
| 467 | - $c = substr($c, 19, strlen($c) - 19 - 20); |
|
| 467 | + $c = substr($c, 19, strlen($c) - 19 - 20); |
|
| 468 | 468 | $compress .= $c; |
| 469 | 469 | continue; |
| 470 | 470 | } elseif (strtolower(substr($c, 0, 12)) == '<nocompress>') { |
| 471 | - $c = substr($c, 12, strlen($c) - 12 - 13); |
|
| 471 | + $c = substr($c, 12, strlen($c) - 12 - 13); |
|
| 472 | 472 | $compress .= $c; |
| 473 | 473 | continue; |
| 474 | 474 | } elseif (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') { |
@@ -516,14 +516,14 @@ discard block |
||
| 516 | 516 | * @return mixed |
| 517 | 517 | */ |
| 518 | 518 | static public function htmlReplaceXcx(string $content):string { |
| 519 | - $content = str_replace("\r\n","",$content);//出除回车和换行符 |
|
| 520 | - $content = preg_replace("/style=\".*?\"/si",'',$content);//style样式 |
|
| 521 | - $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"],['<text class="wx-strong">','</text>'],$content);//strong |
|
| 522 | - $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"],['<view class="wx-p">','</view>'],$content);//p |
|
| 523 | - $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"],['<text class="wx-a">','</text>'],$content);//a |
|
| 524 | - $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"],['<text class="wx-span">','</text>'],$content);//span |
|
| 525 | - $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"],['<view class="wx-h">','</view>'],$content);//h |
|
| 526 | - $content = preg_replace("/<img.*?/si",'<image class="wx-img"',$content);//img |
|
| 519 | + $content = str_replace("\r\n", "", $content); //出除回车和换行符 |
|
| 520 | + $content = preg_replace("/style=\".*?\"/si", '', $content); //style样式 |
|
| 521 | + $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"], ['<text class="wx-strong">', '</text>'], $content); //strong |
|
| 522 | + $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"], ['<view class="wx-p">', '</view>'], $content); //p |
|
| 523 | + $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"], ['<text class="wx-a">', '</text>'], $content); //a |
|
| 524 | + $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"], ['<text class="wx-span">', '</text>'], $content); //span |
|
| 525 | + $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"], ['<view class="wx-h">', '</view>'], $content); //h |
|
| 526 | + $content = preg_replace("/<img.*?/si", '<image class="wx-img"', $content); //img |
|
| 527 | 527 | return $content; |
| 528 | 528 | } |
| 529 | 529 | |
@@ -535,8 +535,8 @@ discard block |
||
| 535 | 535 | * @return string |
| 536 | 536 | */ |
| 537 | 537 | static public function pReplaceSpan(string $content):string { |
| 538 | - $content = str_replace(["\r","\n","\t"],'',$content); |
|
| 539 | - $content = preg_replace(["/<p/si", "/<\/p>/si"],['<span','</span><br>'],$content);//p |
|
| 538 | + $content = str_replace(["\r", "\n", "\t"], '', $content); |
|
| 539 | + $content = preg_replace(["/<p/si", "/<\/p>/si"], ['<span', '</span><br>'], $content); //p |
|
| 540 | 540 | return $content; |
| 541 | 541 | } |
| 542 | 542 | |
@@ -547,10 +547,10 @@ discard block |
||
| 547 | 547 | * @param string $keyword |
| 548 | 548 | * @return string |
| 549 | 549 | */ |
| 550 | - static public function filterPunctuation($keyword){ |
|
| 551 | - $keyword = str_replace(["\r\n", "\r", "\n"," "," "], "", trim($keyword));//删除空格 |
|
| 552 | - $keyword = preg_replace('# #','',$keyword); |
|
| 553 | - $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",'',$keyword); |
|
| 550 | + static public function filterPunctuation($keyword) { |
|
| 551 | + $keyword = str_replace(["\r\n", "\r", "\n", " ", " "], "", trim($keyword)); //删除空格 |
|
| 552 | + $keyword = preg_replace('# #', '', $keyword); |
|
| 553 | + $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/", '', $keyword); |
|
| 554 | 554 | return $keyword; |
| 555 | 555 | } |
| 556 | 556 | |
@@ -562,9 +562,9 @@ discard block |
||
| 562 | 562 | * @param string $allowable_tags |
| 563 | 563 | * @return string |
| 564 | 564 | */ |
| 565 | - static public function stripTags($content,$allowable_tags = '<font>'){ |
|
| 566 | - $content = strip_tags($content,$allowable_tags);//替换标签 |
|
| 567 | - $content = str_replace(["\r\n", "\r", "\n"," "], "", trim($content));//删除空格 |
|
| 565 | + static public function stripTags($content, $allowable_tags = '<font>') { |
|
| 566 | + $content = strip_tags($content, $allowable_tags); //替换标签 |
|
| 567 | + $content = str_replace(["\r\n", "\r", "\n", " "], "", trim($content)); //删除空格 |
|
| 568 | 568 | return $content; |
| 569 | 569 | } |
| 570 | 570 | |
@@ -19,11 +19,11 @@ |
||
| 19 | 19 | public static function getIp(){ |
| 20 | 20 | if(!empty($_SERVER["HTTP_CLIENT_IP"])){ |
| 21 | 21 | $cip = $_SERVER["HTTP_CLIENT_IP"]; |
| 22 | - }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
| 22 | + } else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
| 23 | 23 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 24 | - }else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
| 24 | + } else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
| 25 | 25 | $cip = $_SERVER["REMOTE_ADDR"]; |
| 26 | - }else{ |
|
| 26 | + } else{ |
|
| 27 | 27 | $cip = ''; |
| 28 | 28 | } |
| 29 | 29 | preg_match("/[\d\.]{7,15}/", $cip, $cips); |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Description: Tool.php. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -class Tool{ |
|
| 11 | +class Tool { |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Description: 获取ip |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | * Updater: |
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | - public static function getIp(){ |
|
| 20 | - if(!empty($_SERVER["HTTP_CLIENT_IP"])){ |
|
| 19 | + public static function getIp() { |
|
| 20 | + if (!empty($_SERVER["HTTP_CLIENT_IP"])) { |
|
| 21 | 21 | $cip = $_SERVER["HTTP_CLIENT_IP"]; |
| 22 | - }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
| 22 | + } else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { |
|
| 23 | 23 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 24 | - }else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
| 24 | + } else if (!empty($_SERVER["REMOTE_ADDR"])) { |
|
| 25 | 25 | $cip = $_SERVER["REMOTE_ADDR"]; |
| 26 | - }else{ |
|
| 26 | + } else { |
|
| 27 | 27 | $cip = ''; |
| 28 | 28 | } |
| 29 | 29 | preg_match("/[\d\.]{7,15}/", $cip, $cips); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * Updater: |
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | - public static function getOrigin(){ |
|
| 42 | + public static function getOrigin() { |
|
| 43 | 43 | $origin = ''; |
| 44 | 44 | if (isset($_SERVER['HTTP_X_ORIGINAL_FOR'])) { |
| 45 | 45 | $origin = $_SERVER['HTTP_X_ORIGINAL_FOR']; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | 'mobile' |
| 105 | 105 | ); |
| 106 | 106 | // 从HTTP_USER_AGENT中查找手机浏览器的关键字 |
| 107 | - if (preg_match("/(" . implode('|', $clientKeyWords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { |
|
| 107 | + if (preg_match("/(".implode('|', $clientKeyWords).")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { |
|
| 108 | 108 | return true; |
| 109 | 109 | } |
| 110 | 110 | } |