PHPackages                             cdyun/php-tool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. cdyun/php-tool

ActiveLibrary[HTTP &amp; Networking](/categories/http)

cdyun/php-tool
==============

PHP8.1+通用工具包，包含数组处理、字符串处理、时间处理、加解密、IP、地理计算、Curl、全局辅助方法等功能

v2.0.4(2mo ago)2281MITPHPPHP &gt;=8.1

Since Sep 22Pushed 2mo agoCompare

[ Source](https://github.com/cdyun303/php-tool)[ Packagist](https://packagist.org/packages/cdyun/php-tool)[ RSS](/packages/cdyun-php-tool/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (3)Versions (17)Used By (1)

PHP8.1+ 通用工具包
=============

[](#php81-通用工具包)

- [PHP8.1+ 通用工具包](#php81-%E9%80%9A%E7%94%A8%E5%B7%A5%E5%85%B7%E5%8C%85)
- [简介](#%E7%AE%80%E4%BB%8B)
- [安装](#%E5%AE%89%E8%A3%85)
- [模块化目录](#%E6%A8%A1%E5%9D%97%E5%8C%96%E7%9B%AE%E5%BD%95)
    - [数组处理模块](#%E6%95%B0%E7%BB%84%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95)
        - [兼容性说明](#%E5%85%BC%E5%AE%B9%E6%80%A7%E8%AF%B4%E6%98%8E)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B)
            - [树形结构转换](#%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84%E8%BD%AC%E6%8D%A2)
                - [tree() / toTree() - 数组转树形结构](#tree--totree---%E6%95%B0%E7%BB%84%E8%BD%AC%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84)
                - [list() - 树形结构转数组](#list---%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84%E8%BD%AC%E6%95%B0%E7%BB%84)
                - [level() - 数组转层级结构](#level---%E6%95%B0%E7%BB%84%E8%BD%AC%E5%B1%82%E7%BA%A7%E7%BB%93%E6%9E%84)
                - [path() - 数组转路径结构](#path---%E6%95%B0%E7%BB%84%E8%BD%AC%E8%B7%AF%E5%BE%84%E7%BB%93%E6%9E%84)
                - [getParentIds() - 获取叶子节点的所有父节点ID](#getparentids---%E8%8E%B7%E5%8F%96%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E6%89%80%E6%9C%89%E7%88%B6%E8%8A%82%E7%82%B9id)
                - [getChildIds() - 获取所有子节点的ID](#getchildids---%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84id)
            - [数组访问和操作](#%E6%95%B0%E7%BB%84%E8%AE%BF%E9%97%AE%E5%92%8C%E6%93%8D%E4%BD%9C)
                - [deepMerge() - 数组深度合并](#deepmerge---%E6%95%B0%E7%BB%84%E6%B7%B1%E5%BA%A6%E5%90%88%E5%B9%B6)
                - [get() - 数组获取值（支持点语法）](#get---%E6%95%B0%E7%BB%84%E8%8E%B7%E5%8F%96%E5%80%BC%E6%94%AF%E6%8C%81%E7%82%B9%E8%AF%AD%E6%B3%95)
                - [set() - 数组设置值](#set---%E6%95%B0%E7%BB%84%E8%AE%BE%E7%BD%AE%E5%80%BC)
                - [has() - 数组判断是否存在键](#has---%E6%95%B0%E7%BB%84%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E9%94%AE)
                - [only() - 数组仅保留指定键](#only---%E6%95%B0%E7%BB%84%E4%BB%85%E4%BF%9D%E7%95%99%E6%8C%87%E5%AE%9A%E9%94%AE)
                - [except() - 数组排除指定键](#except---%E6%95%B0%E7%BB%84%E6%8E%92%E9%99%A4%E6%8C%87%E5%AE%9A%E9%94%AE)
            - [多维数组处理](#%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E5%A4%84%E7%90%86)
                - [group() - 多维数组分组](#group---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E5%88%86%E7%BB%84)
                - [count() - 多维数组统计](#count---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E7%BB%9F%E8%AE%A1)
                - [sum() - 多维数组求和](#sum---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E6%B1%82%E5%92%8C)
                - [avg() - 多维数组求平均值](#avg---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E6%B1%82%E5%B9%B3%E5%9D%87%E5%80%BC)
                - [max() - 多维数组求最大值](#max---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E6%B1%82%E6%9C%80%E5%A4%A7%E5%80%BC)
                - [min() - 多维数组求最小值](#min---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E6%B1%82%E6%9C%80%E5%B0%8F%E5%80%BC)
            - [PHP 8.4+数组函数](#php-84%E6%95%B0%E7%BB%84%E5%87%BD%E6%95%B0)
                - [first() - 数组首元素](#first---%E6%95%B0%E7%BB%84%E9%A6%96%E5%85%83%E7%B4%A0)
                - [last() - 数组尾元素](#last---%E6%95%B0%E7%BB%84%E5%B0%BE%E5%85%83%E7%B4%A0)
                - [find() - 查找满足条件的元素](#find---%E6%9F%A5%E6%89%BE%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E5%85%83%E7%B4%A0)
                - [findKey() - 查找满足条件的键名](#findkey---%E6%9F%A5%E6%89%BE%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E9%94%AE%E5%90%8D)
                - [any() - 检查是否存在满足条件的元素](#any---%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E5%85%83%E7%B4%A0)
                - [all() - 检查是否所有元素都满足条件](#all---%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E9%83%BD%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6)
            - [数组查找和判断](#%E6%95%B0%E7%BB%84%E6%9F%A5%E6%89%BE%E5%92%8C%E5%88%A4%E6%96%AD)
                - [map() - 数组映射](#map---%E6%95%B0%E7%BB%84%E6%98%A0%E5%B0%84)
                - [filter() - 数组过滤](#filter---%E6%95%B0%E7%BB%84%E8%BF%87%E6%BB%A4)
                - [reduce() - 数组归约](#reduce---%E6%95%B0%E7%BB%84%E5%BD%92%E7%BA%A6)
                - [find() - 查找满足条件的第一个元素的键值](#find---%E6%9F%A5%E6%89%BE%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E9%94%AE%E5%80%BC)
                - [findKey() - 查找满足条件的第一个元素的键名](#findkey---%E6%9F%A5%E6%89%BE%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E9%94%AE%E5%90%8D)
                - [some() - 检查是否存在满足条件的元素（别名方法）](#some---%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E5%85%83%E7%B4%A0%E5%88%AB%E5%90%8D%E6%96%B9%E6%B3%95)
                - [every() - 检查是否所有元素都满足条件（别名方法）](#every---%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E9%83%BD%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E5%88%AB%E5%90%8D%E6%96%B9%E6%B3%95)
                - [contains() - 数组是否包含指定元素](#contains---%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E6%8C%87%E5%AE%9A%E5%85%83%E7%B4%A0)
                - [containsKey() - 数组是否包含指定键名](#containskey---%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E6%8C%87%E5%AE%9A%E9%94%AE%E5%90%8D)
                - [isEmpty() - 数组是否为空](#isempty---%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A9%BA)
                - [isAssoc() - 数组是否为关联数组](#isassoc---%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E4%B8%BA%E5%85%B3%E8%81%94%E6%95%B0%E7%BB%84)
                - [isIndexed() - 数组是否为索引数组](#isindexed---%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E4%B8%BA%E7%B4%A2%E5%BC%95%E6%95%B0%E7%BB%84)
            - [数组排序](#%E6%95%B0%E7%BB%84%E6%8E%92%E5%BA%8F)
                - [sort() - 升序/降序](#sort---%E5%8D%87%E5%BA%8F%E9%99%8D%E5%BA%8F)
                - [multiSort() - 多维数组排序](#multisort---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E6%8E%92%E5%BA%8F)
                - [reverse() - 数组反转](#reverse---%E6%95%B0%E7%BB%84%E5%8F%8D%E8%BD%AC)
                - [shuffle() - 数组打乱](#shuffle---%E6%95%B0%E7%BB%84%E6%89%93%E4%B9%B1)
            - [数组去重](#%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D)
                - [unique() - 数组去重](#unique---%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D)
                - [multiUnique() - 多维数组去重](#multiunique---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D)
            - [数组分页和切片](#%E6%95%B0%E7%BB%84%E5%88%86%E9%A1%B5%E5%92%8C%E5%88%87%E7%89%87)
                - [paginate() - 数组分页](#paginate---%E6%95%B0%E7%BB%84%E5%88%86%E9%A1%B5)
                - [slice() - 数组切片](#slice---%E6%95%B0%E7%BB%84%E5%88%87%E7%89%87)
                - [chunk() - 数组分割](#chunk---%E6%95%B0%E7%BB%84%E5%88%86%E5%89%B2)
            - [数组合并和差集](#%E6%95%B0%E7%BB%84%E5%90%88%E5%B9%B6%E5%92%8C%E5%B7%AE%E9%9B%86)
                - [merge() - 数组合并](#merge---%E6%95%B0%E7%BB%84%E5%90%88%E5%B9%B6)
                - [mergeRecursive() - 数组合并（保留键名）](#mergerecursive---%E6%95%B0%E7%BB%84%E5%90%88%E5%B9%B6%E4%BF%9D%E7%95%99%E9%94%AE%E5%90%8D)
                - [diff() - 数组差集](#diff---%E6%95%B0%E7%BB%84%E5%B7%AE%E9%9B%86)
                - [diffKey() - 数组差集（带键名）](#diffkey---%E6%95%B0%E7%BB%84%E5%B7%AE%E9%9B%86%E5%B8%A6%E9%94%AE%E5%90%8D)
                - [intersect() - 数组交集](#intersect---%E6%95%B0%E7%BB%84%E4%BA%A4%E9%9B%86)
                - [intersectKey() - 数组交集（带键名）](#intersectkey---%E6%95%B0%E7%BB%84%E4%BA%A4%E9%9B%86%E5%B8%A6%E9%94%AE%E5%90%8D)
            - [数组转换](#%E6%95%B0%E7%BB%84%E8%BD%AC%E6%8D%A2)
                - [toJson() - 多维数组转JSON](#tojson---%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84%E8%BD%ACjson)
                - [fromJson() - JSON转多维数组](#fromjson---json%E8%BD%AC%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84)
                - [flatten() - 数组扁平化](#flatten---%E6%95%B0%E7%BB%84%E6%89%81%E5%B9%B3%E5%8C%96)
                - [keys() - 数组键名](#keys---%E6%95%B0%E7%BB%84%E9%94%AE%E5%90%8D)
                - [values() - 数组键值](#values---%E6%95%B0%E7%BB%84%E9%94%AE%E5%80%BC)
                - [flip() - 键名与键值翻转](#flip---%E9%94%AE%E5%90%8D%E4%B8%8E%E9%94%AE%E5%80%BC%E7%BF%BB%E8%BD%AC)
                - [column() - 数组列提取](#column---%E6%95%B0%E7%BB%84%E5%88%97%E6%8F%90%E5%8F%96)
            - [数组键值操作](#%E6%95%B0%E7%BB%84%E9%94%AE%E5%80%BC%E6%93%8D%E4%BD%9C)
                - [mapKeys() - 数组映射键名](#mapkeys---%E6%95%B0%E7%BB%84%E6%98%A0%E5%B0%84%E9%94%AE%E5%90%8D)
                - [mapValues() - 数组映射键值](#mapvalues---%E6%95%B0%E7%BB%84%E6%98%A0%E5%B0%84%E9%94%AE%E5%80%BC)
                - [combine() - 数组合并键值](#combine---%E6%95%B0%E7%BB%84%E5%90%88%E5%B9%B6%E9%94%AE%E5%80%BC)
                - [fillKeys() - 数组填充键值](#fillkeys---%E6%95%B0%E7%BB%84%E5%A1%AB%E5%85%85%E9%94%AE%E5%80%BC)
                - [fill() - 数组填充](#fill---%E6%95%B0%E7%BB%84%E5%A1%AB%E5%85%85)
            - [数组随机操作](#%E6%95%B0%E7%BB%84%E9%9A%8F%E6%9C%BA%E6%93%8D%E4%BD%9C)
                - [random() - 数组随机元素](#random---%E6%95%B0%E7%BB%84%E9%9A%8F%E6%9C%BA%E5%85%83%E7%B4%A0)
                - [randomMany() - 数组随机多个元素](#randommany---%E6%95%B0%E7%BB%84%E9%9A%8F%E6%9C%BA%E5%A4%9A%E4%B8%AA%E5%85%83%E7%B4%A0)
            - [数组元素操作](#%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0%E6%93%8D%E4%BD%9C)
                - [shift() - 数组弹出第一个元素](#shift---%E6%95%B0%E7%BB%84%E5%BC%B9%E5%87%BA%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0)
                - [pop() - 数组弹出最后一个元素](#pop---%E6%95%B0%E7%BB%84%E5%BC%B9%E5%87%BA%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0)
                - [unshift() - 数组头部添加元素](#unshift---%E6%95%B0%E7%BB%84%E5%A4%B4%E9%83%A8%E6%B7%BB%E5%8A%A0%E5%85%83%E7%B4%A0)
                - [push() - 数组尾部添加元素](#push---%E6%95%B0%E7%BB%84%E5%B0%BE%E9%83%A8%E6%B7%BB%E5%8A%A0%E5%85%83%E7%B4%A0)
                - [remove() - 数组删除指定元素](#remove---%E6%95%B0%E7%BB%84%E5%88%A0%E9%99%A4%E6%8C%87%E5%AE%9A%E5%85%83%E7%B4%A0)
                - [removeKey() - 数组删除指定键名](#removekey---%E6%95%B0%E7%BB%84%E5%88%A0%E9%99%A4%E6%8C%87%E5%AE%9A%E9%94%AE%E5%90%8D)
    - [字符串处理模块](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-1)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-1)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-1)
            - [脱敏](#%E8%84%B1%E6%95%8F)
                - [mask() - 字符串脱敏](#mask---%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%84%B1%E6%95%8F)
                - [maskPhone() - 手机号脱敏](#maskphone---%E6%89%8B%E6%9C%BA%E5%8F%B7%E8%84%B1%E6%95%8F)
                - [maskEmail() - 邮箱脱敏](#maskemail---%E9%82%AE%E7%AE%B1%E8%84%B1%E6%95%8F)
                - [maskIdCard() - 身份证号脱敏](#maskidcard---%E8%BA%AB%E4%BB%BD%E8%AF%81%E5%8F%B7%E8%84%B1%E6%95%8F)
                - [maskBankCard() - 银行卡号脱敏](#maskbankcard---%E9%93%B6%E8%A1%8C%E5%8D%A1%E5%8F%B7%E8%84%B1%E6%95%8F)
                - [maskName() - 姓名脱敏](#maskname---%E5%A7%93%E5%90%8D%E8%84%B1%E6%95%8F)
            - [字符串长度和截断](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6%E5%92%8C%E6%88%AA%E6%96%AD)
                - [length() - 字符串长度](#length---%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6)
                - [truncate() - 字符串截断](#truncate---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%88%AA%E6%96%AD)
                - [limit() - 字符串限制长度](#limit---%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%99%90%E5%88%B6%E9%95%BF%E5%BA%A6)
                - [wordTruncate() - 字符串单词截断](#wordtruncate---%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8D%95%E8%AF%8D%E6%88%AA%E6%96%AD)
            - [字符串命名转换](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%91%BD%E5%90%8D%E8%BD%AC%E6%8D%A2)
                - [snake() - 驼峰转下划线](#snake---%E9%A9%BC%E5%B3%B0%E8%BD%AC%E4%B8%8B%E5%88%92%E7%BA%BF)
                - [toSnake() - 驼峰命名转下划线命名(支持数组键名)](#tosnake---%E9%A9%BC%E5%B3%B0%E5%91%BD%E5%90%8D%E8%BD%AC%E4%B8%8B%E5%88%92%E7%BA%BF%E5%91%BD%E5%90%8D%E6%94%AF%E6%8C%81%E6%95%B0%E7%BB%84%E9%94%AE%E5%90%8D)
                - [camel() - 下划线转驼峰](#camel---%E4%B8%8B%E5%88%92%E7%BA%BF%E8%BD%AC%E9%A9%BC%E5%B3%B0)
                - [toCamel() - 下划线命名转驼峰命名(支持数组键名)](#tocamel---%E4%B8%8B%E5%88%92%E7%BA%BF%E5%91%BD%E5%90%8D%E8%BD%AC%E9%A9%BC%E5%B3%B0%E5%91%BD%E5%90%8D%E6%94%AF%E6%8C%81%E6%95%B0%E7%BB%84%E9%94%AE%E5%90%8D)
                - [studly() - 首字母大写驼峰命名](#studly---%E9%A6%96%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%86%99%E9%A9%BC%E5%B3%B0%E5%91%BD%E5%90%8D)
                - [ucfirst() - 首字母大写](#ucfirst---%E9%A6%96%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%86%99)
                - [lcfirst() - 首字母小写](#lcfirst---%E9%A6%96%E5%AD%97%E6%AF%8D%E5%B0%8F%E5%86%99)
                - [ucwords() - 单词首字母大写](#ucwords---%E5%8D%95%E8%AF%8D%E9%A6%96%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%86%99)
                - [upper() - 全部大写](#upper---%E5%85%A8%E9%83%A8%E5%A4%A7%E5%86%99)
                - [lower() - 全部小写](#lower---%E5%85%A8%E9%83%A8%E5%B0%8F%E5%86%99)
                - [swap() - 大小写转换](#swap---%E5%A4%A7%E5%B0%8F%E5%86%99%E8%BD%AC%E6%8D%A2)
                - [title() - 标题格式](#title---%E6%A0%87%E9%A2%98%E6%A0%BC%E5%BC%8F)
            - [字符串查找和判断](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%9F%A5%E6%89%BE%E5%92%8C%E5%88%A4%E6%96%AD)
                - [contains() - 是否包含子串](#contains---%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E5%AD%90%E4%B8%B2)
                - [startsWith() - 是否以子串开头](#startswith---%E6%98%AF%E5%90%A6%E4%BB%A5%E5%AD%90%E4%B8%B2%E5%BC%80%E5%A4%B4)
                - [endsWith() - 是否以子串结尾](#endswith---%E6%98%AF%E5%90%A6%E4%BB%A5%E5%AD%90%E4%B8%B2%E7%BB%93%E5%B0%BE)
                - [pos() - 子串首次出现位置](#pos---%E5%AD%90%E4%B8%B2%E9%A6%96%E6%AC%A1%E5%87%BA%E7%8E%B0%E4%BD%8D%E7%BD%AE)
                - [rpos() - 子串最后一次出现位置](#rpos---%E5%AD%90%E4%B8%B2%E6%9C%80%E5%90%8E%E4%B8%80%E6%AC%A1%E5%87%BA%E7%8E%B0%E4%BD%8D%E7%BD%AE)
                - [count() - 子串出现次数](#count---%E5%AD%90%E4%B8%B2%E5%87%BA%E7%8E%B0%E6%AC%A1%E6%95%B0)
                - [match() - 字符串是否匹配正则](#match---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%AF%E5%90%A6%E5%8C%B9%E9%85%8D%E6%AD%A3%E5%88%99)
            - [字符串替换](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%9B%BF%E6%8D%A2)
                - [replace() - 字符串替换](#replace---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%9B%BF%E6%8D%A2)
                - [replaceArray() - 字符串批量替换](#replacearray---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%89%B9%E9%87%8F%E6%9B%BF%E6%8D%A2)
                - [replaceRegex() - 字符串正则替换](#replaceregex---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%AD%A3%E5%88%99%E6%9B%BF%E6%8D%A2)
                - [substrReplace() - 字符串截取并替换](#substrreplace---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%88%AA%E5%8F%96%E5%B9%B6%E6%9B%BF%E6%8D%A2)
            - [字符串分割和连接](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%88%86%E5%89%B2%E5%92%8C%E8%BF%9E%E6%8E%A5)
                - [split() - 字符串分割](#split---%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%88%86%E5%89%B2)
                - [toArray() - 字符串分割为数组](#toarray---%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%88%86%E5%89%B2%E4%B8%BA%E6%95%B0%E7%BB%84)
                - [fromArray() - 数组连接为字符串](#fromarray---%E6%95%B0%E7%BB%84%E8%BF%9E%E6%8E%A5%E4%B8%BA%E5%AD%97%E7%AC%A6%E4%B8%B2)
                - [join() - 字符串连接](#join---%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BF%9E%E6%8E%A5)
                - [concat() - 字符串拼接](#concat---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%8B%BC%E6%8E%A5)
            - [字符串去除空白](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8E%BB%E9%99%A4%E7%A9%BA%E7%99%BD)
                - [trim() - 去除首尾空白](#trim---%E5%8E%BB%E9%99%A4%E9%A6%96%E5%B0%BE%E7%A9%BA%E7%99%BD)
                - [ltrim() - 去除左侧空白](#ltrim---%E5%8E%BB%E9%99%A4%E5%B7%A6%E4%BE%A7%E7%A9%BA%E7%99%BD)
                - [rtrim() - 去除右侧空白](#rtrim---%E5%8E%BB%E9%99%A4%E5%8F%B3%E4%BE%A7%E7%A9%BA%E7%99%BD)
                - [clean() - 去除所有空白](#clean---%E5%8E%BB%E9%99%A4%E6%89%80%E6%9C%89%E7%A9%BA%E7%99%BD)
            - [字符串填充](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%A1%AB%E5%85%85)
                - [padLeft() - 左侧填充](#padleft---%E5%B7%A6%E4%BE%A7%E5%A1%AB%E5%85%85)
                - [padRight() - 右侧填充](#padright---%E5%8F%B3%E4%BE%A7%E5%A1%AB%E5%85%85)
                - [padBoth() - 两侧填充](#padboth---%E4%B8%A4%E4%BE%A7%E5%A1%AB%E5%85%85)
            - [字符串重复](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%87%8D%E5%A4%8D)
                - [repeat() - 字符串重复](#repeat---%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%87%8D%E5%A4%8D)
                - [reverse() - 字符串反转](#reverse---%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8F%8D%E8%BD%AC)
            - [字符串随机](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%9A%8F%E6%9C%BA)
                - [random() - 生成随机字符串](#random---%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E5%AD%97%E7%AC%A6%E4%B8%B2)
                - [numeric() - 生成随机数字字符串](#numeric---%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E6%95%B0%E5%AD%97%E5%AD%97%E7%AC%A6%E4%B8%B2)
                - [alpha() - 生成随机字母字符串](#alpha---%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E5%AD%97%E6%AF%8D%E5%AD%97%E7%AC%A6%E4%B8%B2)
            - [字符串编码解码](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%BC%96%E7%A0%81%E8%A7%A3%E7%A0%81)
                - [toBase64() - Base64编码](#tobase64---base64%E7%BC%96%E7%A0%81)
                - [fromBase64() - Base64解码](#frombase64---base64%E8%A7%A3%E7%A0%81)
                - [toUrlEncode() - URL编码](#tourlencode---url%E7%BC%96%E7%A0%81)
                - [fromUrlEncode() - URL解码](#fromurlencode---url%E8%A7%A3%E7%A0%81)
                - [toHtmlEntities() - HTML实体编码](#tohtmlentities---html%E5%AE%9E%E4%BD%93%E7%BC%96%E7%A0%81)
                - [fromHtmlEntities() - HTML实体解码](#fromhtmlentities---html%E5%AE%9E%E4%BD%93%E8%A7%A3%E7%A0%81)
                - [toJson() - JSON编码](#tojson---json%E7%BC%96%E7%A0%81)
                - [fromJson() - JSON解码](#fromjson---json%E8%A7%A3%E7%A0%81)
                - [toXml() - XML编码](#toxml---xml%E7%BC%96%E7%A0%81)
                - [fromXml() - XML解码](#fromxml---xml%E8%A7%A3%E7%A0%81)
                - [toBinary() - 二进制编码](#tobinary---%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%BC%96%E7%A0%81)
                - [fromBinary() - 二进制解码](#frombinary---%E4%BA%8C%E8%BF%9B%E5%88%B6%E8%A7%A3%E7%A0%81)
                - [toHex() - 十六进制编码](#tohex---%E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6%E7%BC%96%E7%A0%81)
                - [fromHex() - 十六进制解码](#fromhex---%E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6%E8%A7%A3%E7%A0%81)
            - [字符串哈希](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%93%88%E5%B8%8C)
                - [md5() - MD5哈希](#md5---md5%E5%93%88%E5%B8%8C)
                - [sha1() - SHA1哈希](#sha1---sha1%E5%93%88%E5%B8%8C)
                - [sha256() - SHA256哈希](#sha256---sha256%E5%93%88%E5%B8%8C)
                - [sha512() - SHA512哈希](#sha512---sha512%E5%93%88%E5%B8%8C)
            - [字符串验证](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%AA%8C%E8%AF%81)
                - [isEmail() - 是否为邮箱](#isemail---%E6%98%AF%E5%90%A6%E4%B8%BA%E9%82%AE%E7%AE%B1)
                - [isUrl() - 是否为URL](#isurl---%E6%98%AF%E5%90%A6%E4%B8%BAurl)
                - [isIp() - 是否为IP地址](#isip---%E6%98%AF%E5%90%A6%E4%B8%BAip%E5%9C%B0%E5%9D%80)
                - [isIpv4() - 是否为IPv4地址](#isipv4---%E6%98%AF%E5%90%A6%E4%B8%BAipv4%E5%9C%B0%E5%9D%80)
                - [isIpv6() - 是否为IPv6地址](#isipv6---%E6%98%AF%E5%90%A6%E4%B8%BAipv6%E5%9C%B0%E5%9D%80)
                - [isPhone() - 是否为手机号](#isphone---%E6%98%AF%E5%90%A6%E4%B8%BA%E6%89%8B%E6%9C%BA%E5%8F%B7)
                - [isIdCard() - 是否为身份证号](#isidcard---%E6%98%AF%E5%90%A6%E4%B8%BA%E8%BA%AB%E4%BB%BD%E8%AF%81%E5%8F%B7)
                - [isBankCard() - 是否为银行卡号](#isbankcard---%E6%98%AF%E5%90%A6%E4%B8%BA%E9%93%B6%E8%A1%8C%E5%8D%A1%E5%8F%B7)
                - [isNumeric() - 是否为数字](#isnumeric---%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B0%E5%AD%97)
                - [isAlpha() - 是否为字母](#isalpha---%E6%98%AF%E5%90%A6%E4%B8%BA%E5%AD%97%E6%AF%8D)
                - [isAlnum() - 是否为字母数字](#isalnum---%E6%98%AF%E5%90%A6%E4%B8%BA%E5%AD%97%E6%AF%8D%E6%95%B0%E5%AD%97)
                - [isHex() - 是否为十六进制](#ishex---%E6%98%AF%E5%90%A6%E4%B8%BA%E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6)
                - [isBinary() - 是否为二进制](#isbinary---%E6%98%AF%E5%90%A6%E4%B8%BA%E4%BA%8C%E8%BF%9B%E5%88%B6)
                - [isJson() - 是否为JSON](#isjson---%E6%98%AF%E5%90%A6%E4%B8%BAjson)
                - [isXml() - 是否为XML](#isxml---%E6%98%AF%E5%90%A6%E4%B8%BAxml)
                - [isSerialized() - 是否为序列化数据](#isserialized---%E6%98%AF%E5%90%A6%E4%B8%BA%E5%BA%8F%E5%88%97%E5%8C%96%E6%95%B0%E6%8D%AE)
                - [isBase64() - 是否为Base64](#isbase64---%E6%98%AF%E5%90%A6%E4%B8%BAbase64)
            - [字符串转换](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2)
                - [toArray() - 字符串转数组](#toarray---%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%95%B0%E7%BB%84)
                - [fromArray() - 数组转字符串](#fromarray---%E6%95%B0%E7%BB%84%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2)
                - [toObject() - 字符串转对象](#toobject---%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E5%AF%B9%E8%B1%A1)
                - [fromObject() - 对象转字符串](#fromobject---%E5%AF%B9%E8%B1%A1%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2)
                - [toQuery() - 字符串转查询字符串](#toquery---%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%9F%A5%E8%AF%A2%E5%AD%97%E7%AC%A6%E4%B8%B2)
                - [fromQuery() - 查询字符串转数组](#fromquery---%E6%9F%A5%E8%AF%A2%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%95%B0%E7%BB%84)
            - [字符串格式化](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A0%BC%E5%BC%8F%E5%8C%96)
                - [format() - 字符串格式化](#format---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A0%BC%E5%BC%8F%E5%8C%96)
                - [template() - 字符串模板渲染](#template---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A8%A1%E6%9D%BF%E6%B8%B2%E6%9F%93)
                - [indent() - 字符串缩进](#indent---%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%BC%A9%E8%BF%9B)
                - [unindent() - 字符串去除缩进](#unindent---%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8E%BB%E9%99%A4%E7%BC%A9%E8%BF%9B)
            - [字符串字符操作](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AD%97%E7%AC%A6%E6%93%8D%E4%BD%9C)
                - [first() - 获取字符串首字符](#first---%E8%8E%B7%E5%8F%96%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%A6%96%E5%AD%97%E7%AC%A6)
                - [last() - 获取字符串尾字符](#last---%E8%8E%B7%E5%8F%96%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B0%BE%E5%AD%97%E7%AC%A6)
                - [firstN() - 获取字符串前N个字符](#firstn---%E8%8E%B7%E5%8F%96%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%89%8Dn%E4%B8%AA%E5%AD%97%E7%AC%A6)
                - [lastN() - 获取字符串后N个字符](#lastn---%E8%8E%B7%E5%8F%96%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%90%8En%E4%B8%AA%E5%AD%97%E7%AC%A6)
                - [removeFirst() - 去除首字符](#removefirst---%E5%8E%BB%E9%99%A4%E9%A6%96%E5%AD%97%E7%AC%A6)
                - [removeLast() - 去除尾字符](#removelast---%E5%8E%BB%E9%99%A4%E5%B0%BE%E5%AD%97%E7%AC%A6)
                - [removeFirstN() - 去除前N个字符](#removefirstn---%E5%8E%BB%E9%99%A4%E5%89%8Dn%E4%B8%AA%E5%AD%97%E7%AC%A6)
                - [removeLastN() - 去除后N个字符](#removelastn---%E5%8E%BB%E9%99%A4%E5%90%8En%E4%B8%AA%E5%AD%97%E7%AC%A6)
            - [字符串统计](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%BB%9F%E8%AE%A1)
                - [count() - 统计子串出现次数](#count---%E7%BB%9F%E8%AE%A1%E5%AD%90%E4%B8%B2%E5%87%BA%E7%8E%B0%E6%AC%A1%E6%95%B0)
                - [wordCount() - 统计单词数](#wordcount---%E7%BB%9F%E8%AE%A1%E5%8D%95%E8%AF%8D%E6%95%B0)
                - [charCount() - 统计字符数](#charcount---%E7%BB%9F%E8%AE%A1%E5%AD%97%E7%AC%A6%E6%95%B0)
                - [byteLength() - 统计字节长度](#bytelength---%E7%BB%9F%E8%AE%A1%E5%AD%97%E8%8A%82%E9%95%BF%E5%BA%A6)
            - [字符串安全](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AE%89%E5%85%A8)
                - [escapeHtml() - 转义HTML特殊字符](#escapehtml---%E8%BD%AC%E4%B9%89html%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6)
                - [escapeSql() - 转义SQL特殊字符](#escapesql---%E8%BD%AC%E4%B9%89sql%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6)
                - [escapeJs() - 转义JavaScript特殊字符](#escapejs---%E8%BD%AC%E4%B9%89javascript%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6)
                - [escapeRegex() - 转义正则表达式特殊字符](#escaperegex---%E8%BD%AC%E4%B9%89%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6)
            - [字符串比较](#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%AF%94%E8%BE%83)
                - [compare() - 字符串比较](#compare---%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%AF%94%E8%BE%83)
                - [similarity() - 字符串相似度](#similarity---%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E4%BC%BC%E5%BA%A6)
                - [distance() - 字符串编辑距离](#distance---%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%BC%96%E8%BE%91%E8%B7%9D%E7%A6%BB)
    - [时间处理模块](#%E6%97%B6%E9%97%B4%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-2)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-2)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-2)
            - [时间格式化](#%E6%97%B6%E9%97%B4%E6%A0%BC%E5%BC%8F%E5%8C%96)
                - [format() - 格式化时间](#format---%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%97%B6%E9%97%B4)
                - [now() - 获取当前时间](#now---%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%B6%E9%97%B4)
                - [today() - 获取今天日期](#today---%E8%8E%B7%E5%8F%96%E4%BB%8A%E5%A4%A9%E6%97%A5%E6%9C%9F)
                - [yesterday() - 获取昨天日期](#yesterday---%E8%8E%B7%E5%8F%96%E6%98%A8%E5%A4%A9%E6%97%A5%E6%9C%9F)
                - [tomorrow() - 获取明天日期](#tomorrow---%E8%8E%B7%E5%8F%96%E6%98%8E%E5%A4%A9%E6%97%A5%E6%9C%9F)
            - [时间计算](#%E6%97%B6%E9%97%B4%E8%AE%A1%E7%AE%97)
                - [add() - 时间加法](#add---%E6%97%B6%E9%97%B4%E5%8A%A0%E6%B3%95)
                - [sub() - 时间减法](#sub---%E6%97%B6%E9%97%B4%E5%87%8F%E6%B3%95)
                - [diff() - 时间差](#diff---%E6%97%B6%E9%97%B4%E5%B7%AE)
                - [diffForHumans() - 人性化时间差](#diffforhumans---%E4%BA%BA%E6%80%A7%E5%8C%96%E6%97%B6%E9%97%B4%E5%B7%AE)
            - [周日期范围](#%E5%91%A8%E6%97%A5%E6%9C%9F%E8%8C%83%E5%9B%B4)
                - [weekStart() - 获取本周开始时间](#weekstart---%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%91%A8%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)
                - [weekEnd() - 获取本周结束时间](#weekend---%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%91%A8%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)
                - [lastWeekStart() - 获取上周开始时间](#lastweekstart---%E8%8E%B7%E5%8F%96%E4%B8%8A%E5%91%A8%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)
                - [lastWeekEnd() - 获取上周结束时间](#lastweekend---%E8%8E%B7%E5%8F%96%E4%B8%8A%E5%91%A8%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)
            - [月日期范围](#%E6%9C%88%E6%97%A5%E6%9C%9F%E8%8C%83%E5%9B%B4)
                - [monthStart() - 获取本月开始时间](#monthstart---%E8%8E%B7%E5%8F%96%E6%9C%AC%E6%9C%88%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)
                - [monthEnd() - 获取本月结束时间](#monthend---%E8%8E%B7%E5%8F%96%E6%9C%AC%E6%9C%88%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)
                - [lastMonthStart() - 获取上月开始时间](#lastmonthstart---%E8%8E%B7%E5%8F%96%E4%B8%8A%E6%9C%88%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)
                - [lastMonthEnd() - 获取上月结束时间](#lastmonthend---%E8%8E%B7%E5%8F%96%E4%B8%8A%E6%9C%88%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)
            - [年日期范围](#%E5%B9%B4%E6%97%A5%E6%9C%9F%E8%8C%83%E5%9B%B4)
                - [yearStart() - 获取本年开始时间](#yearstart---%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%B9%B4%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)
                - [yearEnd() - 获取本年结束时间](#yearend---%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%B9%B4%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)
                - [lastYearStart() - 获取上年开始时间](#lastyearstart---%E8%8E%B7%E5%8F%96%E4%B8%8A%E5%B9%B4%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)
                - [lastYearEnd() - 获取上年结束时间](#lastyearend---%E8%8E%B7%E5%8F%96%E4%B8%8A%E5%B9%B4%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)
            - [时间判断](#%E6%97%B6%E9%97%B4%E5%88%A4%E6%96%AD)
                - [between() - 判断是否在某个时间区间内](#between---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E5%9C%A8%E6%9F%90%E4%B8%AA%E6%97%B6%E9%97%B4%E5%8C%BA%E9%97%B4%E5%86%85)
                - [isToday() - 判断是否是今天](#istoday---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E4%BB%8A%E5%A4%A9)
                - [isYesterday() - 判断是否是昨天](#isyesterday---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E6%98%A8%E5%A4%A9)
                - [isTomorrow() - 判断是否是明天](#istomorrow---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E6%98%8E%E5%A4%A9)
                - [isThisWeek() - 判断是否是本周](#isthisweek---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E6%9C%AC%E5%91%A8)
                - [isThisMonth() - 判断是否是本月](#isthismonth---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E6%9C%AC%E6%9C%88)
                - [isThisYear() - 判断是否是本年](#isthisyear---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E6%9C%AC%E5%B9%B4)
            - [日期信息获取](#%E6%97%A5%E6%9C%9F%E4%BF%A1%E6%81%AF%E8%8E%B7%E5%8F%96)
                - [daysInMonth() - 获取某个月的天数](#daysinmonth---%E8%8E%B7%E5%8F%96%E6%9F%90%E4%B8%AA%E6%9C%88%E7%9A%84%E5%A4%A9%E6%95%B0)
                - [dayOfWeek() - 获取某天是周几](#dayofweek---%E8%8E%B7%E5%8F%96%E6%9F%90%E5%A4%A9%E6%98%AF%E5%91%A8%E5%87%A0)
                - [dayOfWeekName() - 获取某天是周几（中文名称）](#dayofweekname---%E8%8E%B7%E5%8F%96%E6%9F%90%E5%A4%A9%E6%98%AF%E5%91%A8%E5%87%A0%E4%B8%AD%E6%96%87%E5%90%8D%E7%A7%B0)
                - [dayOfYear() - 获取某天是本年第几天](#dayofyear---%E8%8E%B7%E5%8F%96%E6%9F%90%E5%A4%A9%E6%98%AF%E6%9C%AC%E5%B9%B4%E7%AC%AC%E5%87%A0%E5%A4%A9)
                - [weekOfYear() - 获取某天是本年第几周](#weekofyear---%E8%8E%B7%E5%8F%96%E6%9F%90%E5%A4%A9%E6%98%AF%E6%9C%AC%E5%B9%B4%E7%AC%AC%E5%87%A0%E5%91%A8)
            - [年龄计算](#%E5%B9%B4%E9%BE%84%E8%AE%A1%E7%AE%97)
                - [age() - 计算年龄](#age---%E8%AE%A1%E7%AE%97%E5%B9%B4%E9%BE%84)
            - [时间戳转换](#%E6%97%B6%E9%97%B4%E6%88%B3%E8%BD%AC%E6%8D%A2)
                - [toTimestamp() - 时间字符串转时间戳](#totimestamp---%E6%97%B6%E9%97%B4%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%97%B6%E9%97%B4%E6%88%B3)
                - [toMillisecond() - 时间戳转毫秒](#tomillisecond---%E6%97%B6%E9%97%B4%E6%88%B3%E8%BD%AC%E6%AF%AB%E7%A7%92)
                - [fromMillisecond() - 毫秒转时间戳](#frommillisecond---%E6%AF%AB%E7%A7%92%E8%BD%AC%E6%97%B6%E9%97%B4%E6%88%B3)
                - [millisecond() - 获取当前毫秒时间戳](#millisecond---%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%AF%AB%E7%A7%92%E6%97%B6%E9%97%B4%E6%88%B3)
                - [microsecond() - 获取当前微秒时间戳](#microsecond---%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E5%BE%AE%E7%A7%92%E6%97%B6%E9%97%B4%E6%88%B3)
                - [microtime() - 获取当前时间戳（带微秒）](#microtime---%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%B6%E9%97%B4%E6%88%B3%E5%B8%A6%E5%BE%AE%E7%A7%92)
            - [时区操作](#%E6%97%B6%E5%8C%BA%E6%93%8D%E4%BD%9C)
                - [timezone() - 获取当前时区](#timezone---%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%B6%E5%8C%BA)
                - [setTimezone() - 设置时区](#settimezone---%E8%AE%BE%E7%BD%AE%E6%97%B6%E5%8C%BA)
        - [实际应用场景](#%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF)
    - [数学计算处理模块](#%E6%95%B0%E5%AD%A6%E8%AE%A1%E7%AE%97%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-3)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-3)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-3)
            - [基础运算](#%E5%9F%BA%E7%A1%80%E8%BF%90%E7%AE%97)
                - [add() - 高精度加法](#add---%E9%AB%98%E7%B2%BE%E5%BA%A6%E5%8A%A0%E6%B3%95)
                - [sub() - 高精度减法](#sub---%E9%AB%98%E7%B2%BE%E5%BA%A6%E5%87%8F%E6%B3%95)
                - [mul() - 高精度乘法](#mul---%E9%AB%98%E7%B2%BE%E5%BA%A6%E4%B9%98%E6%B3%95)
                - [div() - 高精度除法](#div---%E9%AB%98%E7%B2%BE%E5%BA%A6%E9%99%A4%E6%B3%95)
                - [mod() - 取模运算](#mod---%E5%8F%96%E6%A8%A1%E8%BF%90%E7%AE%97)
                - [pow() - 幂运算](#pow---%E5%B9%82%E8%BF%90%E7%AE%97)
                - [sqrt() - 平方根运算](#sqrt---%E5%B9%B3%E6%96%B9%E6%A0%B9%E8%BF%90%E7%AE%97)
            - [取整运算](#%E5%8F%96%E6%95%B4%E8%BF%90%E7%AE%97)
                - [round() - 四舍五入](#round---%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5)
                - [ceil() - 向上取整](#ceil---%E5%90%91%E4%B8%8A%E5%8F%96%E6%95%B4)
                - [floor() - 向下取整](#floor---%E5%90%91%E4%B8%8B%E5%8F%96%E6%95%B4)
            - [比较运算](#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97)
                - [compare() - 比较两个数的大小](#compare---%E6%AF%94%E8%BE%83%E4%B8%A4%E4%B8%AA%E6%95%B0%E7%9A%84%E5%A4%A7%E5%B0%8F)
                - [equal() - 判断两个数是否相等](#equal---%E5%88%A4%E6%96%AD%E4%B8%A4%E4%B8%AA%E6%95%B0%E6%98%AF%E5%90%A6%E7%9B%B8%E7%AD%89)
            - [格式化](#%E6%A0%BC%E5%BC%8F%E5%8C%96)
                - [format() - 格式化数字](#format---%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%95%B0%E5%AD%97)
            - [三角函数](#%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0)
                - [sin() - 正弦函数](#sin---%E6%AD%A3%E5%BC%A6%E5%87%BD%E6%95%B0)
                - [cos() - 余弦函数](#cos---%E4%BD%99%E5%BC%A6%E5%87%BD%E6%95%B0)
                - [tan() - 正切函数](#tan---%E6%AD%A3%E5%88%87%E5%87%BD%E6%95%B0)
                - [asin() - 反正弦函数](#asin---%E5%8F%8D%E6%AD%A3%E5%BC%A6%E5%87%BD%E6%95%B0)
                - [acos() - 反余弦函数](#acos---%E5%8F%8D%E4%BD%99%E5%BC%A6%E5%87%BD%E6%95%B0)
                - [atan() - 反正切函数](#atan---%E5%8F%8D%E6%AD%A3%E5%88%87%E5%87%BD%E6%95%B0)
            - [对数运算](#%E5%AF%B9%E6%95%B0%E8%BF%90%E7%AE%97)
                - [ln() - 自然对数（以e为底）](#ln---%E8%87%AA%E7%84%B6%E5%AF%B9%E6%95%B0%E4%BB%A5e%E4%B8%BA%E5%BA%95)
                - [log10() - 常用对数（以10为底）](#log10---%E5%B8%B8%E7%94%A8%E5%AF%B9%E6%95%B0%E4%BB%A510%E4%B8%BA%E5%BA%95)
                - [log() - 自定义底数对数](#log---%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BA%95%E6%95%B0%E5%AF%B9%E6%95%B0)
            - [角度转换](#%E8%A7%92%E5%BA%A6%E8%BD%AC%E6%8D%A2)
                - [rad2deg() - 弧度转角度](#rad2deg---%E5%BC%A7%E5%BA%A6%E8%BD%AC%E8%A7%92%E5%BA%A6)
                - [deg2rad() - 角度转弧度](#deg2rad---%E8%A7%92%E5%BA%A6%E8%BD%AC%E5%BC%A7%E5%BA%A6)
            - [数值操作](#%E6%95%B0%E5%80%BC%E6%93%8D%E4%BD%9C)
                - [abs() - 绝对值](#abs---%E7%BB%9D%E5%AF%B9%E5%80%BC)
                - [factorial() - 阶乘](#factorial---%E9%98%B6%E4%B9%98)
                - [gcd() - 最大公约数](#gcd---%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0)
                - [lcm() - 最小公倍数](#lcm---%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0)
            - [金融计算](#%E9%87%91%E8%9E%8D%E8%AE%A1%E7%AE%97)
                - [percentage() - 百分比计算](#percentage---%E7%99%BE%E5%88%86%E6%AF%94%E8%AE%A1%E7%AE%97)
                - [discount() - 折扣计算](#discount---%E6%8A%98%E6%89%A3%E8%AE%A1%E7%AE%97)
                - [tax() - 税费计算](#tax---%E7%A8%8E%E8%B4%B9%E8%AE%A1%E7%AE%97)
                - [taxIncluded() - 含税金额计算](#taxincluded---%E5%90%AB%E7%A8%8E%E9%87%91%E9%A2%9D%E8%AE%A1%E7%AE%97)
                - [taxExcluded() - 不含税金额计算](#taxexcluded---%E4%B8%8D%E5%90%AB%E7%A8%8E%E9%87%91%E9%A2%9D%E8%AE%A1%E7%AE%97)
                - [simpleInterest() - 简单利息计算](#simpleinterest---%E7%AE%80%E5%8D%95%E5%88%A9%E6%81%AF%E8%AE%A1%E7%AE%97)
                - [compoundInterest() - 复利计算](#compoundinterest---%E5%A4%8D%E5%88%A9%E8%AE%A1%E7%AE%97)
            - [随机数生成](#%E9%9A%8F%E6%9C%BA%E6%95%B0%E7%94%9F%E6%88%90)
                - [random() - 生成指定范围内的随机数](#random---%E7%94%9F%E6%88%90%E6%8C%87%E5%AE%9A%E8%8C%83%E5%9B%B4%E5%86%85%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0)
            - [范围检查](#%E8%8C%83%E5%9B%B4%E6%A3%80%E6%9F%A5)
                - [inRange() - 数值范围检查](#inrange---%E6%95%B0%E5%80%BC%E8%8C%83%E5%9B%B4%E6%A3%80%E6%9F%A5)
                - [clamp() - 限制数值范围](#clamp---%E9%99%90%E5%88%B6%E6%95%B0%E5%80%BC%E8%8C%83%E5%9B%B4)
            - [数值判断](#%E6%95%B0%E5%80%BC%E5%88%A4%E6%96%AD)
                - [isPositive() - 判断是否为正数](#ispositive---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E6%AD%A3%E6%95%B0)
                - [isNegative() - 判断是否为负数](#isnegative---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E8%B4%9F%E6%95%B0)
                - [isZero() - 判断是否为零](#iszero---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E9%9B%B6)
                - [isEven() - 判断是否为偶数](#iseven---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E5%81%B6%E6%95%B0)
                - [isOdd() - 判断是否为奇数](#isodd---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E5%A5%87%E6%95%B0)
                - [isPrime() - 判断是否为质数](#isprime---%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E8%B4%A8%E6%95%B0)
                - [isValid() - 判断数值是否有效](#isvalid---%E5%88%A4%E6%96%AD%E6%95%B0%E5%80%BC%E6%98%AF%E5%90%A6%E6%9C%89%E6%95%88)
            - [插值运算](#%E6%8F%92%E5%80%BC%E8%BF%90%E7%AE%97)
                - [lerp() - 线性插值](#lerp---%E7%BA%BF%E6%80%A7%E6%8F%92%E5%80%BC)
            - [统计分析](#%E7%BB%9F%E8%AE%A1%E5%88%86%E6%9E%90)
                - [average() - 平均值计算](#average---%E5%B9%B3%E5%9D%87%E5%80%BC%E8%AE%A1%E7%AE%97)
                - [median() - 中位数计算](#median---%E4%B8%AD%E4%BD%8D%E6%95%B0%E8%AE%A1%E7%AE%97)
                - [mode() - 众数计算](#mode---%E4%BC%97%E6%95%B0%E8%AE%A1%E7%AE%97)
                - [standardDeviation() - 标准差计算](#standarddeviation---%E6%A0%87%E5%87%86%E5%B7%AE%E8%AE%A1%E7%AE%97)
        - [实际应用场景](#%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-1)
    - [地理位置处理模块](#%E5%9C%B0%E7%90%86%E4%BD%8D%E7%BD%AE%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-4)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-4)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-4)
            - [distance() - 计算两个坐标之间的距离](#distance---%E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E5%9D%90%E6%A0%87%E4%B9%8B%E9%97%B4%E7%9A%84%E8%B7%9D%E7%A6%BB)
            - [isValid() - 坐标验证](#isvalid---%E5%9D%90%E6%A0%87%E9%AA%8C%E8%AF%81)
            - [midpoint() - 计算两个坐标之间的中点](#midpoint---%E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E5%9D%90%E6%A0%87%E4%B9%8B%E9%97%B4%E7%9A%84%E4%B8%AD%E7%82%B9)
            - [bearing() - 计算两个坐标之间的方位角](#bearing---%E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E5%9D%90%E6%A0%87%E4%B9%8B%E9%97%B4%E7%9A%84%E6%96%B9%E4%BD%8D%E8%A7%92)
            - [toRadians() - 将角度转换为弧度](#toradians---%E5%B0%86%E8%A7%92%E5%BA%A6%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%BC%A7%E5%BA%A6)
            - [toDegrees() - 将弧度转换为角度](#todegrees---%E5%B0%86%E5%BC%A7%E5%BA%A6%E8%BD%AC%E6%8D%A2%E4%B8%BA%E8%A7%92%E5%BA%A6)
            - [toDMS() - 将十进制度数转换为度分秒（DMS）](#todms---%E5%B0%86%E5%8D%81%E8%BF%9B%E5%88%B6%E5%BA%A6%E6%95%B0%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%BA%A6%E5%88%86%E7%A7%92dms)
            - [toDecimal() - 将度分秒（DMS）转换为十进制度数](#todecimal---%E5%B0%86%E5%BA%A6%E5%88%86%E7%A7%92dms%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%8D%81%E8%BF%9B%E5%88%B6%E5%BA%A6%E6%95%B0)
            - [gcj02ToBd09() - GCJ02坐标转BD09坐标](#gcj02tobd09---gcj02%E5%9D%90%E6%A0%87%E8%BD%ACbd09%E5%9D%90%E6%A0%87)
            - [bd09ToGcj02() - BD09坐标转GCJ02坐标](#bd09togcj02---bd09%E5%9D%90%E6%A0%87%E8%BD%ACgcj02%E5%9D%90%E6%A0%87)
            - [wgs84ToGcj02() - WGS84坐标转GCJ02坐标（中国火星坐标系）](#wgs84togcj02---wgs84%E5%9D%90%E6%A0%87%E8%BD%ACgcj02%E5%9D%90%E6%A0%87%E4%B8%AD%E5%9B%BD%E7%81%AB%E6%98%9F%E5%9D%90%E6%A0%87%E7%B3%BB)
            - [gcj02ToWgs84() - GCJ02坐标转WGS84坐标](#gcj02towgs84---gcj02%E5%9D%90%E6%A0%87%E8%BD%ACwgs84%E5%9D%90%E6%A0%87)
            - [wgs84ToBd09() - WGS84坐标转BD09坐标](#wgs84tobd09---wgs84%E5%9D%90%E6%A0%87%E8%BD%ACbd09%E5%9D%90%E6%A0%87)
            - [bd09ToWgs84() - BD09坐标转WGS84坐标](#bd09towgs84---bd09%E5%9D%90%E6%A0%87%E8%BD%ACwgs84%E5%9D%90%E6%A0%87)
    - [IP地址处理模块](#ip%E5%9C%B0%E5%9D%80%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-5)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-5)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-5)
            - [getRealIp() - 获取真实客户端IP地址](#getrealip---%E8%8E%B7%E5%8F%96%E7%9C%9F%E5%AE%9E%E5%AE%A2%E6%88%B7%E7%AB%AFip%E5%9C%B0%E5%9D%80)
            - [isValid() - 验证IP地址格式是否有效](#isvalid---%E9%AA%8C%E8%AF%81ip%E5%9C%B0%E5%9D%80%E6%A0%BC%E5%BC%8F%E6%98%AF%E5%90%A6%E6%9C%89%E6%95%88)
            - [isPrivate() - 检查IP地址是否为私有/内部地址](#isprivate---%E6%A3%80%E6%9F%A5ip%E5%9C%B0%E5%9D%80%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A7%81%E6%9C%89%E5%86%85%E9%83%A8%E5%9C%B0%E5%9D%80)
            - [getVersion() - 获取IP地址版本](#getversion---%E8%8E%B7%E5%8F%96ip%E5%9C%B0%E5%9D%80%E7%89%88%E6%9C%AC)
            - [toLong() - 将IP地址转换为长整数](#tolong---%E5%B0%86ip%E5%9C%B0%E5%9D%80%E8%BD%AC%E6%8D%A2%E4%B8%BA%E9%95%BF%E6%95%B4%E6%95%B0)
            - [fromLong() - 将长整数转换为IP地址](#fromlong---%E5%B0%86%E9%95%BF%E6%95%B4%E6%95%B0%E8%BD%AC%E6%8D%A2%E4%B8%BAip%E5%9C%B0%E5%9D%80)
            - [getLocation() - 获取IP地址位置信息](#getlocation---%E8%8E%B7%E5%8F%96ip%E5%9C%B0%E5%9D%80%E4%BD%8D%E7%BD%AE%E4%BF%A1%E6%81%AF)
            - [isFromCountry() - 检查IP地址是否来自特定国家](#isfromcountry---%E6%A3%80%E6%9F%A5ip%E5%9C%B0%E5%9D%80%E6%98%AF%E5%90%A6%E6%9D%A5%E8%87%AA%E7%89%B9%E5%AE%9A%E5%9B%BD%E5%AE%B6)
            - [getType() - 获取IP地址类型](#gettype---%E8%8E%B7%E5%8F%96ip%E5%9C%B0%E5%9D%80%E7%B1%BB%E5%9E%8B)
    - [代码生成模块](#%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-6)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-6)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-6)
            - [uuid() - 生成uuid](#uuid---%E7%94%9F%E6%88%90uuid)
            - [orderNo() - 生成订单号](#orderno---%E7%94%9F%E6%88%90%E8%AE%A2%E5%8D%95%E5%8F%B7)
            - [inviteCode() - 生成邀请码](#invitecode---%E7%94%9F%E6%88%90%E9%82%80%E8%AF%B7%E7%A0%81)
            - [urlSafeCode() - 生成URL安全码](#urlsafecode---%E7%94%9F%E6%88%90url%E5%AE%89%E5%85%A8%E7%A0%81)
            - [registerCode() - 生成注册码](#registercode---%E7%94%9F%E6%88%90%E6%B3%A8%E5%86%8C%E7%A0%81)
    - [加解密处理模块](#%E5%8A%A0%E8%A7%A3%E5%AF%86%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-7)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-7)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-7)
            - [Crypto - 加密引擎说明](#crypto---%E5%8A%A0%E5%AF%86%E5%BC%95%E6%93%8E%E8%AF%B4%E6%98%8E)
            - [Crypto - 加密模式说明](#crypto---%E5%8A%A0%E5%AF%86%E6%A8%A1%E5%BC%8F%E8%AF%B4%E6%98%8E)
            - [Crypto - 基础加解密](#crypto---%E5%9F%BA%E7%A1%80%E5%8A%A0%E8%A7%A3%E5%AF%86)
            - [Crypto - 静态方法调用](#crypto---%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95%E8%B0%83%E7%94%A8)
            - [md5() - MD5加密（支持加盐）](#md5---md5%E5%8A%A0%E5%AF%86%E6%94%AF%E6%8C%81%E5%8A%A0%E7%9B%90)
            - [passwordHash() - 密码哈希](#passwordhash---%E5%AF%86%E7%A0%81%E5%93%88%E5%B8%8C)
            - [passwordVerify() - 密码哈希验证](#passwordverify---%E5%AF%86%E7%A0%81%E5%93%88%E5%B8%8C%E9%AA%8C%E8%AF%81)
            - [Crypto - HMAC签名](#crypto---hmac%E7%AD%BE%E5%90%8D)
            - [Crypto - SSL对称加解密](#crypto---ssl%E5%AF%B9%E7%A7%B0%E5%8A%A0%E8%A7%A3%E5%AF%86)
            - [Crypto - 错误处理](#crypto---%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86)
        - [使用场景](#%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF)
    - [HTTP请求处理模块](#http%E8%AF%B7%E6%B1%82%E5%A4%84%E7%90%86%E6%A8%A1%E5%9D%97)
        - [特性](#%E7%89%B9%E6%80%A7-8)
        - [核心方法](#%E6%A0%B8%E5%BF%83%E6%96%B9%E6%B3%95-8)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-8)
            - [setDefaultOptions() - 设置默认配置](#setdefaultoptions---%E8%AE%BE%E7%BD%AE%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE)
            - [getDefaultOptions() - 获取默认配置](#getdefaultoptions---%E8%8E%B7%E5%8F%96%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE)
            - [reset() - 重置客户端实例](#reset---%E9%87%8D%E7%BD%AE%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%AE%9E%E4%BE%8B)
            - [options() - OPTIONS请求](#options---options%E8%AF%B7%E6%B1%82)
            - [head() - HEAD请求](#head---head%E8%AF%B7%E6%B1%82)
            - [get() - GET请求](#get---get%E8%AF%B7%E6%B1%82)
            - [post() - POST请求](#post---post%E8%AF%B7%E6%B1%82)
            - [postForm() - POST表单请求](#postform---post%E8%A1%A8%E5%8D%95%E8%AF%B7%E6%B1%82)
            - [postMultipart() - POST文件上传请求](#postmultipart---post%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E8%AF%B7%E6%B1%82)
            - [put() - PUT请求](#put---put%E8%AF%B7%E6%B1%82)
            - [putForm() - PUT表单请求](#putform---put%E8%A1%A8%E5%8D%95%E8%AF%B7%E6%B1%82)
            - [delete() - PUT请求](#delete---put%E8%AF%B7%E6%B1%82)
            - [patch() - PATCH请求](#patch---patch%E8%AF%B7%E6%B1%82)
    - [目录文件处理](#%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%A4%84%E7%90%86)
        - [使用示例](#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B-9)
            - [scanFolder() - 搜索指定路径下的【直系】文件夹](#scanfolder---%E6%90%9C%E7%B4%A2%E6%8C%87%E5%AE%9A%E8%B7%AF%E5%BE%84%E4%B8%8B%E7%9A%84%E7%9B%B4%E7%B3%BB%E6%96%87%E4%BB%B6%E5%A4%B9)
            - [getFileContent() - 获取文件内容](#getfilecontent---%E8%8E%B7%E5%8F%96%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9)
            - [listFileContent() - 获取指定路径文件夹下所有直系文件夹中所有指定文件名的php文件内容](#listfilecontent---%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E8%B7%AF%E5%BE%84%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%8B%E6%89%80%E6%9C%89%E7%9B%B4%E7%B3%BB%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%AD%E6%89%80%E6%9C%89%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E5%90%8D%E7%9A%84php%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9)
            - [deleteDirFile() - 清除指定文件夹下文件](#deletedirfile---%E6%B8%85%E9%99%A4%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%8B%E6%96%87%E4%BB%B6)
            - [scanFile() - 搜索文件夹下全部文件，指定扩展名，暂时不支持中文文件名](#scanfile---%E6%90%9C%E7%B4%A2%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%8B%E5%85%A8%E9%83%A8%E6%96%87%E4%BB%B6%E6%8C%87%E5%AE%9A%E6%89%A9%E5%B1%95%E5%90%8D%E6%9A%82%E6%97%B6%E4%B8%8D%E6%94%AF%E6%8C%81%E4%B8%AD%E6%96%87%E6%96%87%E4%BB%B6%E5%90%8D)
            - [scanFileTree() - 搜索文件夹下全部文件返回树形结构，指定扩展名，暂时不支持中文文件名](#scanfiletree---%E6%90%9C%E7%B4%A2%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%8B%E5%85%A8%E9%83%A8%E6%96%87%E4%BB%B6%E8%BF%94%E5%9B%9E%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84%E6%8C%87%E5%AE%9A%E6%89%A9%E5%B1%95%E5%90%8D%E6%9A%82%E6%97%B6%E4%B8%8D%E6%94%AF%E6%8C%81%E4%B8%AD%E6%96%87%E6%96%87%E4%BB%B6%E5%90%8D)
- [版本要求](#%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82)
- [许可证](#%E8%AE%B8%E5%8F%AF%E8%AF%81)

简介
==

[](#简介)

这是一个基于PHP8.1+特性开发的模块化通用工具包，提供了数组处理、字符串处理、时间处理、加解密、消息体、IP地址处理、地理计算、全局辅助方法等功能。支持对象和静态两种调用方式，兼容进程和协程环境。

安装
==

[](#安装)

```
composer require cdyun/php-tool

```

模块化目录
=====

[](#模块化目录)

工具包采用清晰的模块化架构，每个模块专注于特定领域的功能：

```
├── src/
│   ├── Arr.php       // 数组处理主类
│   ├── Str.php       // 字符串处理主类
│   ├── Time.php      // 时间处理主类
│   ├── Math.php      // 数学计算主类
│   ├── Geo.php       // 地理位置主类
│   ├── Ip.php        // IP地址处理主类
│   ├── Crypto.php    // 加解密主类（命名简洁）
│   ├── Generate.php  // 代码生成工具类
│   ├── Curl.php      // HTTP请求主类
│   ├── Dir.php      // 目录文件处理
│   ├── helpers.php   // 全局辅助函数文件
│   ├──......             // 其他│
│
├── composer.json         // Composer配置
├── README.md             // 使用文档

```

数组处理模块
------

[](#数组处理模块)

### 特性

[](#特性)

- ✅ 树形结构转换（数组转树、树转数组）
- ✅ 层级结构转换
- ✅ 路径结构转换
- ✅ 常用数组操作（get/set/has/only/except）
- ✅ 数组深度合并
- ✅ 多维数组分组
- ✅ 多维数组统计（count/sum/avg/max/min）
- ✅ 多维数组转JSON/JSON转数组
- ✅ 非递归算法，支持大数据量
- ✅ 支持点语法和数组嵌套键访问

### 核心方法

[](#核心方法)

方法名功能描述调用示例[`first()`](#arrfirst---%E6%95%B0%E7%BB%84%E9%A6%96%E5%85%83%E7%B4%A0)获取第一个元素`Arr::first([1, 2, 3])`[`last()`](#arrlast---%E6%95%B0%E7%BB%84%E5%B0%BE%E5%85%83%E7%B4%A0)获取最后一个元素`Arr::last([1, 2, 3])`[`find()`](#arrfind---%E6%9F%A5%E6%89%BE%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E5%85%83%E7%B4%A0)查找满足条件的元素`Arr::find([1, 2, 3], fn($n) => $n > 1)`[`tree()`](#arrtree---%E6%95%B0%E7%BB%84%E8%BD%AC%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84)数组转树形结构`Arr::tree($list, 'id', 'pid')`[`list()`](#arrlist---%E6%A0%91%E5%BD%A2%E7%BB%93%E6%9E%84%E8%BD%AC%E6%95%B0%E7%BB%84)树形结构转数组`Arr::list($tree)`[`deepMerge()`](#arrdeepmerge---%E6%95%B0%E7%BB%84%E6%B7%B1%E5%BA%A6%E5%90%88%E5%B9%B6)深度合并数组`Arr::deepMerge($arr1, $arr2)`### 兼容性说明

[](#兼容性说明)

数组处理模块会自动检测PHP版本，在PHP 8.4+环境下使用原生数组函数以获得最佳性能：

- `array_first()` - 获取数组第一个元素
- `array_last()` - 获取数组最后一个元素
- `array_find()` - 查找满足条件的元素
- `array_find_key()` - 查找满足条件的键名
- `array_any()` - 检查是否存在满足条件的元素
- `array_all()` - 检查是否所有元素都满足条件

在PHP 8.4以下版本，模块会使用兼容的实现，确保代码在不同PHP版本下都能正常运行。

### 使用示例

[](#使用示例)

#### 树形结构转换

[](#树形结构转换)

##### tree() / toTree() - 数组转树形结构

[](#tree--totree---数组转树形结构)

```
use Cdyun\PhpTool\Arr;

$data = [
    ['id' => 1, 'name' => '部门1', 'parent_id' => 0],
    ['id' => 2, 'name' => '部门2', 'parent_id' => 1],
    ['id' => 3, 'name' => '部门3', 'parent_id' => 1],
    ['id' => 4, 'name' => '部门4', 'parent_id' => 2],
    ['id' => 5, 'name' => '部门5', 'parent_id' => 100]
];

// 按指定根节点ID，将扁平化数组转换为树形结构，会过滤掉非指定根节点及子节点的数据
$tree = Arr::toTree($data, 5, 'id', 'parent_id', 'children');
// 输出:
// [
//     [
//         'id' => 5,
//         'name' => '部门5',
//         'parent_id' => 100,
//         'children' => []
//     ]
// ]

// 数组转树形结构
$tree = Arr::tree($data, 'id', 'parent_id', 'children');
// 输出:
// [
//     [
//         'id' => 1,
//         'name' => '部门1',
//         'parent_id' => 0,
//         'children' => [
//             [
//                 'id' => 2,
//                 'name' => '部门2',
//                 'parent_id' => 1,
//                 'children' => [
//                     ['id' => 4, 'name' => '部门4', 'parent_id' => 2, 'children' => []]
//                 ]
//             ],
//             [
//                 'id' => 3,
//                 'name' => '部门3',
//                 'parent_id' => 1,
//                 'children' => []
//             ]
//         ]
//     ],
//     [
//         'id' => 5,
//         'name' => '部门5',
//         'parent_id' => 100,
//         'children' => []
//     ]
// ]
```

##### list() - 树形结构转数组

[](#list---树形结构转数组)

```
$flat = Arr::list($tree, 'children');
```

##### level() - 数组转层级结构

[](#level---数组转层级结构)

```
$level = Arr::level($data, 'id', 'parent_id', 'level');
// 输出:
// [
//     ['id' => 1, 'name' => '部门1', 'parent_id' => 0, 'level' => 1],
//     ['id' => 2, 'name' => '部门2', 'parent_id' => 1, 'level' => 2],
//     ['id' => 3, 'name' => '部门3', 'parent_id' => 1, 'level' => 2],
//     ['id' => 4, 'name' => '部门4', 'parent_id' => 2, 'level' => 3]
// ]
```

##### path() - 数组转路径结构

[](#path---数组转路径结构)

```
$path = Arr::path($data, 'id', 'parent_id', 'name', 'path', '/');
// 输出:
// [
//     ['id' => 1, 'name' => '部门1', 'parent_id' => 0, 'path' => '部门1'],
//     ['id' => 2, 'name' => '部门2', 'parent_id' => 1, 'path' => '部门1/部门2'],
//     ['id' => 3, 'name' => '部门3', 'parent_id' => 1, 'path' => '部门1/部门3'],
//     ['id' => 4, 'name' => '部门4', 'parent_id' => 2, 'path' => '部门1/部门2/部门4']
// ]
```

##### getParentIds() - 获取叶子节点的所有父节点ID

[](#getparentids---获取叶子节点的所有父节点id)

```
 $arr = [
     ['id' => 1, 'name' => '部门1', 'parent_id' => 0],
     ['id' => 2, 'name' => '部门2', 'parent_id' => 1],
     ['id' => 3, 'name' => '部门3', 'parent_id' => 1],
     ['id' => 4, 'name' => '部门4', 'parent_id' => 2]
 ];
$path = Arr::getParentIds($arr, 4, 'parent_id');
// 输出:
// ['1','2']
```

##### getChildIds() - 获取所有子节点的ID

[](#getchildids---获取所有子节点的id)

```
 $arr = [
     ['id' => 1, 'name' => '部门1', 'parent_id' => 0],
     ['id' => 2, 'name' => '部门2', 'parent_id' => 1],
     ['id' => 3, 'name' => '部门3', 'parent_id' => 1],
     ['id' => 4, 'name' => '部门4', 'parent_id' => 2]
 ];
 // 不含自身
$path = Arr::getChildIds($arr, 1, 'parent_id',false);
// 输出:
// ['2','3','4']

 // 含自身
$path = Arr::getChildIds($arr, 1, 'parent_id',true);
// 输出:
// ['1','2','3','4']
```

#### 数组访问和操作

[](#数组访问和操作)

##### deepMerge() - 数组深度合并

[](#deepmerge---数组深度合并)

```
use Cdyun\PhpTool\Arr;

$arr1 = [
    'user' => ['name' => '张三', 'age' => 25],
    'settings' => ['theme' => 'dark']
];

$arr2 = [
    'user' => ['age' => 26, 'email' => 'user@example.com'],
    'settings' => ['language' => 'zh-CN']
];

$merged = Arr::deepMerge($arr1, $arr2);
// 输出:
// [
//     'user' => ['name' => '张三', 'age' => 26,'email' => 'user@example.com'],
//     'settings' => ['theme' => 'dark', 'language' => 'zh-CN']
// ]
```

##### get() - 数组获取值（支持点语法）

[](#get---数组获取值支持点语法)

```
$value = Arr::get($arr1, 'user.name'); // '张三'
$value = Arr::get($arr1, ['user', 'age']); // 25
$value = Arr::get($arr1, 'user.email', 'default@example.com'); // 'default@example.com'
```

##### set() - 数组设置值

[](#set---数组设置值)

```
$result = Arr::set($arr1, 'user.age', 26);
```

##### has() - 数组判断是否存在键

[](#has---数组判断是否存在键)

```
$exists = Arr::has($arr1, 'user.name'); // true
$exists = Arr::has($arr1, 'user.email'); // false
```

##### only() - 数组仅保留指定键

[](#only---数组仅保留指定键)

```
$only = Arr::only($arr1, ['user.name', 'user.age']);
// 输出: ['user' => ['name' => '张三', 'age' => 25]]
```

##### except() - 数组排除指定键

[](#except---数组排除指定键)

```
$except = Arr::except($array1, ['settings']);
// 输出: ['user' => ['name' => '张三', 'age' => 25]]
```

#### 多维数组处理

[](#多维数组处理)

##### group() - 多维数组分组

[](#group---多维数组分组)

```
use Cdyun\PhpTool\Arr;

$flatArray = [
    ['id' => 1, 'name' => '部门1', 'parent_id' => 0],
    ['id' => 2, 'name' => '部门2', 'parent_id' => 1],
    ['id' => 3, 'name' => '部门3', 'parent_id' => 1],
    ['id' => 4, 'name' => '部门4', 'parent_id' => 2]
];

// 多维数组分组
$grouped = Arr::group($flatArray, 'parent_id');
// 输出:
// [
//     0 => [['id' => 1, 'name' => '部门1', 'parent_id' => 0]],
//     1 => [
//         ['id' => 2, 'name' => '部门2', 'parent_id' => 1],
//         ['id' => 3, 'name' => '部门3', 'parent_id' => 1]
//     ],
//     2 => [['id' => 4, 'name' => '部门4', 'parent_id' => 2]]
// ]
```

##### count() - 多维数组统计

[](#count---多维数组统计)

```
// 多维数组统计
$count = Arr::count($flatArray, 'parent_id');
// 输出: [0 => 1, 1 => 2, 2 => 1]
```

##### sum() - 多维数组求和

[](#sum---多维数组求和)

```
$sum = Arr::sum($flatArray, 'id'); // 10
```

##### avg() - 多维数组求平均值

[](#avg---多维数组求平均值)

```
$avg = Arr::avg($flatArray, 'id'); // 2.5
```

##### max() - 多维数组求最大值

[](#max---多维数组求最大值)

```
$min = Arr::max($flatArray, 'id'); // 4
```

##### min() - 多维数组求最小值

[](#min---多维数组求最小值)

```
$min = Arr::min($flatArray, 'id'); // 1
```

#### PHP 8.4+数组函数

[](#php-84数组函数)

##### first() - 数组首元素

[](#first---数组首元素)

```
use Cdyun\PhpTool\Arr;

// PHP 8.4+使用原生array_first
$first = Arr::first([1, 2, 3, 4, 5]); // 1
$first = Arr::first([]); // null
```

##### last() - 数组尾元素

[](#last---数组尾元素)

```
// PHP 8.4+使用原生array_last
$last = Arr::last([1, 2, 3, 4, 5]); // 5
$last = Arr::last([]); // null
```

##### find() - 查找满足条件的元素

[](#find---查找满足条件的元素)

```
// PHP 8.4+使用原生array_find
$found = Arr::find([1, 2, 3, 4, 5], fn($n) => $n > 2); // 3
$found = Arr::find([1, 2, 3, 4, 5], fn($n) => $n > 10); // null
```

##### findKey() - 查找满足条件的键名

[](#findkey---查找满足条件的键名)

```
// PHP 8.4+使用原生array_find_key
$foundKey = Arr::findKey(['a' => 1, 'b' => 2, 'c' => 3], fn($n) => $n > 1); // 'b'
$foundKey = Arr::findKey(['a' => 1, 'b' => 2, 'c' => 3], fn($n) => $n > 10); // null
```

##### any() - 检查是否存在满足条件的元素

[](#any---检查是否存在满足条件的元素)

```
// PHP 8.4+使用原生array_any
$hasAny = Arr::any([1, 2, 3, 4, 5], fn($n) => $n > 3); // true
$hasAny = Arr::any([1, 2, 3, 4, 5], fn($n) => $n > 10); // false
```

##### all() - 检查是否所有元素都满足条件

[](#all---检查是否所有元素都满足条件)

```
// PHP 8.4+使用原生array_all
$allMatch = Arr::all([1, 2, 3, 4, 5], fn($n) => $n > 0); // true
$allMatch = Arr::all([1, 2, 3, 4, 5], fn($n) => $n > 2); // false
```

#### 数组查找和判断

[](#数组查找和判断)

##### map() - 数组映射

[](#map---数组映射)

```
$mapped = Arr::map([1, 2, 3, 4, 5], fn($n) => $n * 2); // [2, 4, 6, 8, 10]
```

##### filter() - 数组过滤

[](#filter---数组过滤)

```
$filtered = Arr::filter([1, 2, 3, 4, 5], fn($n) => $n > 2); // [3, 4, 5]
$filtered = Arr::filter([1, 2, 0, null, false]); // [1, 2]（过滤空值）
```

##### reduce() - 数组归约

[](#reduce---数组归约)

```
$sum = Arr::reduce([1, 2, 3, 4, 5], fn($carry, $n) => $carry + $n, 0); // 15
```

##### find() - 查找满足条件的第一个元素的键值

[](#find---查找满足条件的第一个元素的键值)

```
$findVal = Arr::find([1, 2, 3, 4, 5], fn($n) => $n > 3); // 4
$findVal = Arr::find(['a' => 10, 'b' => 20, 'c' => 30], fn($n) => $n > 20); // 30
```

##### findKey() - 查找满足条件的第一个元素的键名

[](#findkey---查找满足条件的第一个元素的键名)

```
$findKeyVal = Arr::findKey([1, 2, 3, 4, 5], fn($n) => $n > 3); // 3
$findKeyVal = Arr::findKey(['a' => 10, 'b' => 20, 'c' => 30], fn($n) => $n > 20); // 'c'
```

##### some() - 检查是否存在满足条件的元素（别名方法）

[](#some---检查是否存在满足条件的元素别名方法)

```
$hasSome = Arr::some([1, 2, 3, 4, 5], fn($n) => $n > 3); // true
```

##### every() - 检查是否所有元素都满足条件（别名方法）

[](#every---检查是否所有元素都满足条件别名方法)

```
$allMatch = Arr::every([1, 2, 3, 4, 5], fn($n) => $n > 0); // true
```

##### contains() - 数组是否包含指定元素

[](#contains---数组是否包含指定元素)

```
$contains = Arr::contains([1, 2, 3, 4, 5], 3); // true
$contains = Arr::contains([1, 2, 3, 4, 5], '3', false); // true（非严格比较）
$contains = Arr::contains([1, 2, 3, 4, 5], '3', true); // false（严格比较）
```

##### containsKey() - 数组是否包含指定键名

[](#containskey---数组是否包含指定键名)

```
$containsKey = Arr::containsKey(['a' => 1, 'b' => 2], 'a'); // true
```

##### isEmpty() - 数组是否为空

[](#isempty---数组是否为空)

```
$isEmpty = Arr::isEmpty([]); // true
$isEmpty = Arr::isEmpty([1, 2, 3]); // false
```

##### isAssoc() - 数组是否为关联数组

[](#isassoc---数组是否为关联数组)

```
$isAssoc = Arr::isAssoc(['a' => 1, 'b' => 2]); // true
$isAssoc = Arr::isAssoc([1, 2, 3]); // false
```

##### isIndexed() - 数组是否为索引数组

[](#isindexed---数组是否为索引数组)

```
$isIndexed = Arr::isIndexed([1, 2, 3]); // true
$isIndexed = Arr::isIndexed(['a' => 1, 'b' => 2]); // false
```

#### 数组排序

[](#数组排序)

```
use Cdyun\PhpTool\Arr;

$users = [
    ['id' => 3, 'name' => '张三', 'age' => 25],
    ['id' => 1, 'name' => '李四', 'age' => 30],
    ['id' => 2, 'name' => '王五', 'age' => 28]
];
```

##### sort() - 升序/降序

[](#sort---升序降序)

```
// 升序
$sorted = Arr::sort($users, 'age', 'asc');
// 输出:
//  [
//      ['id' => 3, 'name' => '张三', 'age' => 25],
//      ['id' => 2, 'name' => '王五', 'age' => 28],
//      ['id' => 1, 'name' => '李四', 'age' => 30]
//  ]

// 降序
$sorted = Arr::sort($users, 'age', 'desc');
// 输出:
//  [
//      ['id' => 1, 'name' => '李四', 'age' => 30],
//      ['id' => 2, 'name' => '王五', 'age' => 28],
//      ['id' => 3, 'name' => '张三', 'age' => 25]
//  ]
```

##### multiSort() - 多维数组排序

[](#multisort---多维数组排序)

```
// 先按age升序，age相同时按id降序
$multiSorted = Arr::multiSort($users, ['age', 'id'], ['asc', 'desc']);
```

##### reverse() - 数组反转

[](#reverse---数组反转)

```
$reversed = Arr::reverse([1, 2, 3, 4, 5]); // [5, 4, 3, 2, 1]
$reversed = Arr::reverse(['a' => 1, 'b' => 2], true); // ['b' => 2, 'a' => 1]（保留键名）
```

##### shuffle() - 数组打乱

[](#shuffle---数组打乱)

```
$shuffled = Arr::shuffle([1, 2, 3, 4, 5]); // 随机打乱顺序
```

#### 数组去重

[](#数组去重)

##### unique() - 数组去重

[](#unique---数组去重)

```
$unique = Arr::unique([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]); // [1, 2, 3, 4]
$unique = Arr::unique([1, '1', 2, '2'], true); // [1, '1', 2, '2]（严格比较）
$unique = Arr::unique([1, '1', 2, '2'], false); // [1, 2]（非严格比较）
```

##### multiUnique() - 多维数组去重

[](#multiunique---多维数组去重)

```
$users = [
    ['id' => 1, 'name' => '张三'],
    ['id' => 2, 'name' => '李四'],
    ['id' => 1, 'name' => '张三']
];
$unique = Arr::multiUnique($users, 'id');
// 输出:
//  [
//      ['id' => 1, 'name' => '张三'],
//      ['id' => 2, 'name' => '李四']
//  ]
```

#### 数组分页和切片

[](#数组分页和切片)

##### paginate() - 数组分页

[](#paginate---数组分页)

```
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
$page1 = Arr::paginate($array, 1, 5); // [1, 2, 3, 4, 5]
$page2 = Arr::paginate($array, 2, 5); // [6, 7, 8, 9, 10]
$page3 = Arr::paginate($array, 3, 5); // [11, 12]
```

##### slice() - 数组切片

[](#slice---数组切片)

```
$sliced = Arr::slice([1, 2, 3, 4, 5], 1, 3); // [2, 3, 4]
$sliced = Arr::slice(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4], 1, 2, true); // ['b' => 2, 'c' => 3]（保留键名）
```

##### chunk() - 数组分割

[](#chunk---数组分割)

```
$chunked = Arr::chunk([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3);
// 输出: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
```

#### 数组合并和差集

[](#数组合并和差集)

##### merge() - 数组合并

[](#merge---数组合并)

```
$merged = Arr::merge([1, 2, 3], [4, 5, 6]); // [1, 2, 3, 4, 5, 6]
```

##### mergeRecursive() - 数组合并（保留键名）

[](#mergerecursive---数组合并保留键名)

```
$merged = Arr::mergeRecursive(['a' => 1], ['b' => 2]); // ['a' => 1, 'b' => 2]
```

##### diff() - 数组差集

[](#diff---数组差集)

```
$diff = Arr::diff([1, 2, 3, 4, 5], [2, 4]); // [1, 3, 5]
```

##### diffKey() - 数组差集（带键名）

[](#diffkey---数组差集带键名)

```
$diff = Arr::diffKey(['a' => 1, 'b' => 2, 'c' => 3], ['b' => 2]); // ['a' => 1, 'c' => 3]
```

##### intersect() - 数组交集

[](#intersect---数组交集)

```
$intersect = Arr::intersect([1, 2, 3, 4, 5], [2, 4, 6]); // [2, 4]
```

##### intersectKey() - 数组交集（带键名）

[](#intersectkey---数组交集带键名)

```
$intersect = Arr::intersectKey(['a' => 1, 'b' => 2, 'c' => 3], ['b' => 2, 'c' => 4]); // ['b' => 2, 'c' => 3]
```

#### 数组转换

[](#数组转换)

##### toJson() - 多维数组转JSON

[](#tojson---多维数组转json)

```
$json = Arr::toJson(['name' => '张三', 'age' => 25]); // '{"name":"张三","age":25}'
```

##### fromJson() - JSON转多维数组

[](#fromjson---json转多维数组)

```
$array = Arr::fromJson('{"name":"张三","age":25}'); // ['name' => '张三', 'age' => 25]
```

##### flatten() - 数组扁平化

[](#flatten---数组扁平化)

```
$flattened = Arr::flatten([1, [2, [3, [4, 5]]]]); // [1, 2, 3, 4, 5]
```

##### keys() - 数组键名

[](#keys---数组键名)

```
$keys = Arr::keys(['a' => 1, 'b' => 2, 'c' => 3]); // ['a', 'b', 'c']
```

##### values() - 数组键值

[](#values---数组键值)

```
$values = Arr::values(['a' => 1, 'b' => 2, 'c' => 3]); // [1, 2, 3]
```

##### flip() - 键名与键值翻转

[](#flip---键名与键值翻转)

```
$flipped = Arr::flip(['a' => 1, 'b' => 2, 'c' => 3]); // [1 => 'a', 2 => 'b', 3 => 'c']
```

##### column() - 数组列提取

[](#column---数组列提取)

```
$users = [
    ['id' => 1, 'name' => '张三', 'age' => 25],
    ['id' => 2, 'name' => '李四', 'age' => 30]
];
$names = Arr::column($users, 'name'); // ['张三', '李四']
$indexed = Arr::column($users, 'name', 'id'); // [1 => '张三', 2 => '李四']
```

#### 数组键值操作

[](#数组键值操作)

##### mapKeys() - 数组映射键名

[](#mapkeys---数组映射键名)

```
$mapped = Arr::mapKeys(['a' => 1, 'b' => 2], fn($key) => strtoupper($key)); // ['A' => 1, 'B' => 2]
```

##### mapValues() - 数组映射键值

[](#mapvalues---数组映射键值)

```
$mapped = Arr::mapValues(['a' => 1, 'b' => 2], fn($value) => $value * 2); // ['a' => 2, 'b' => 4]
```

##### combine() - 数组合并键值

[](#combine---数组合并键值)

```
$combined = Arr::combine(['a', 'b', 'c'], [1, 2, 3]); // ['a' => 1, 'b' => 2, 'c' => 3]
```

##### fillKeys() - 数组填充键值

[](#fillkeys---数组填充键值)

```
$filled = Arr::fillKeys(['a', 'b', 'c'], 0); // ['a' => 0, 'b' => 0, 'c' => 0]
```

##### fill() - 数组填充

[](#fill---数组填充)

```
$filled = Arr::fill(0, 5, 0); // [0, 0, 0, 0, 0]
```

#### 数组随机操作

[](#数组随机操作)

##### random() - 数组随机元素

[](#random---数组随机元素)

```
$random = Arr::random([1, 2, 3, 4, 5]); // 随机返回其中一个元素
```

##### randomMany() - 数组随机多个元素

[](#randommany---数组随机多个元素)

```
$randomMany = Arr::randomMany([1, 2, 3, 4, 5], 3); // 随机返回3个元素
```

#### 数组元素操作

[](#数组元素操作)

```
$array = [1, 2, 3, 4, 5];
```

##### shift() - 数组弹出第一个元素

[](#shift---数组弹出第一个元素)

```
$first = Arr::shift($array); // 1，$array变为[2, 3, 4, 5]
```

##### pop() - 数组弹出最后一个元素

[](#pop---数组弹出最后一个元素)

```
$last = Arr::pop($array); // 5，$array变为[2, 3, 4]
```

##### unshift() - 数组头部添加元素

[](#unshift---数组头部添加元素)

```
$count = Arr::unshift($array, 0); // 4，$array变为[0, 2, 3, 4]
```

##### push() - 数组尾部添加元素

[](#push---数组尾部添加元素)

```
$count = Arr::push($array, 5); // 5，$array变为[0, 2, 3, 4, 5]
```

##### remove() - 数组删除指定元素

[](#remove---数组删除指定元素)

```
$removed = Arr::remove([1, 2, 3, 2, 4, 2], 2); // [1, 3, 4]
```

##### removeKey() - 数组删除指定键名

[](#removekey---数组删除指定键名)

```
$removed = Arr::removeKey(['a' => 1, 'b' => 2, 'c' => 3], 'b'); // ['a' => 1, 'c' => 3]
```

字符串处理模块
-------

[](#字符串处理模块)

### 特性

[](#特性-1)

- ✅ 随机字符串生成
- ✅ 命名转换（驼峰、蛇形、大驼峰）
- ✅ 字符串转义和反转义
- ✅ 字符串修剪
- ✅ 字符串脱敏（手机号、身份证号、邮箱、银行卡号、车牌号、姓名）
- ✅ 字符串验证（手机号、身份证号、邮箱、车牌号、银行卡号）
- ✅ 收货地址解析
- ✅ 字符串格式化和转换
- ✅ 字符串相似度比较
- ✅ 多分隔符字符串分割

### 核心方法

[](#核心方法-1)

方法名功能描述调用示例[`maskPhone()`](#strmaskphone---%E6%89%8B%E6%9C%BA%E5%8F%B7%E8%84%B1%E6%95%8F)手机号脱敏`Str::maskPhone('13800138000')`[`maskEmail()`](#strmaskemail---%E9%82%AE%E7%AE%B1%E8%84%B1%E6%95%8F)邮箱脱敏`Str::maskEmail('user@example.com')`[`camel()`](#strcamel---%E4%B8%8B%E5%88%92%E7%BA%BF%E8%BD%AC%E9%A9%BC%E5%B3%B0)转驼峰命名`Str::camel('hello_world')`[`snake()`](#strsnake---%E9%A9%BC%E5%B3%B0%E8%BD%AC%E4%B8%8B%E5%88%92%E7%BA%BF)转蛇形命名`Str::snake('helloWorld')`[`toBase64()`](#strtobase64---%E8%BD%ACbase64%E7%BC%96%E7%A0%81)转Base64编码`Str::toBase64('hello')`[`fromBase64()`](#strfrombase64---base64%E8%A7%A3%E7%A0%81)Base64解码`Str::fromBase64('aGVsbG8=')`### 使用示例

[](#使用示例-1)

#### 脱敏

[](#脱敏)

##### mask() - 字符串脱敏

[](#mask---字符串脱敏)

```
$masked = Str::mask('13800138000', 3, 4, '*'); // '138****8000'
$masked = Str::mask('user@example.com', 2, 4, '*'); // 'us****@example.com'
```

##### maskPhone() - 手机号脱敏

[](#maskphone---手机号脱敏)

```
$phone = Str::maskPhone('13800138000'); // '138****8000'
$phone = Str::maskPhone('13800138000', 3, 4); // '138****8000'
```

##### maskEmail() - 邮箱脱敏

[](#maskemail---邮箱脱敏)

```
$email = Str::maskEmail('user@example.com'); // 'us***@example.com'
$email = Str::maskEmail('user@example.com', 2, 3); // 'us***@example.com'
```

##### maskIdCard() - 身份证号脱敏

[](#maskidcard---身份证号脱敏)

```
$idCard = Str::maskIdCard('110101199001011234'); // '110101********1234'
$idCard = Str::maskIdCard('110101199001011234', 6, 8); // '110101********1234'
```

##### maskBankCard() - 银行卡号脱敏

[](#maskbankcard---银行卡号脱敏)

```
$bankCard = Str::maskBankCard('6222021234567890123'); // '622202********0123'
$bankCard = Str::maskBankCard('6222021234567890123', 6, 10); // '622202********0123'
```

##### maskName() - 姓名脱敏

[](#maskname---姓名脱敏)

```
$name = Str::maskName('张三'); // '张*'
$name = Str::maskName('欧阳修'); // '欧阳*'
$name = Str::maskName('张三丰', 1, 1); // '张*丰'
```

#### 字符串长度和截断

[](#字符串长度和截断)

##### length() - 字符串长度

[](#length---字符串长度)

```
$length = Str::length('你好世界'); // 4（使用mb_strlen）
```

##### truncate() - 字符串截断

[](#truncate---字符串截断)

```
$truncated = Str::truncate('这是一段很长的文本内容', 10); // '这是一段很长的文...'
$truncated = Str::truncate('这是一段很长的文本内容', 10, '---'); // '这是一段很长的文---'
```

##### limit() - 字符串限制长度

[](#limit---字符串限制长度)

```
$limited = Str::limit('这是一段很长的文本内容', 10); // '这是一段很长的文...'
$limited = Str::limit('短文本', 10); // '短文本'（不超过长度不截断）
```

##### wordTruncate() - 字符串单词截断

[](#wordtruncate---字符串单词截断)

```
$wordTruncate = Str::wordTruncate('This is a long text content', 10); // 'This is a...'
```

#### 字符串命名转换

[](#字符串命名转换)

##### snake() - 驼峰转下划线

[](#snake---驼峰转下划线)

```
$snake = Str::snake('helloWorld'); // 'hello_world'
$snake = Str::snake('HelloWorld'); // 'hello_world'
$snake = Str::snake('HelloWorld', '-'); // 'hello-world'
```

##### toSnake() - 驼峰命名转下划线命名(支持数组键名)

[](#tosnake---驼峰命名转下划线命名支持数组键名)

```
$snake = Str::toSnake('helloWorld'); // 'hello_world'
$snake = Str::toSnake('HelloWorld'); // 'hello_world'
$snake = Str::toSnake(['AaBbCc'=>1]); // ['aa_bb_cc'=>1]
```

##### camel() - 下划线转驼峰

[](#camel---下划线转驼峰)

```
$camel = Str::camel('hello_world'); // 'helloWorld'
$camel = Str::camel('hello-world'); // 'helloWorld'
$camel = Str::camel('hello_world', '-'); // 'helloWorld'
```

##### toCamel() - 下划线命名转驼峰命名(支持数组键名)

[](#tocamel---下划线命名转驼峰命名支持数组键名)

```
$camel = Str::toCamel('hello_world', false); // 'helloWorld'
$camel = Str::toCamel('hello_world', true); // 'HelloWorld'
$camel = Str::toCamel(['aa_bb_cc'=>1], false); // 'aaBbCc'
$camel = Str::toCamel(['aa_bb_cc'=>1], true); // 'AaBbCc'
```

##### studly() - 首字母大写驼峰命名

[](#studly---首字母大写驼峰命名)

```
$camel = Str::studly('hello_world'); // 'HelloWorld'
$camel = Str::studly('hello-world'); // 'HelloWorld'
$camel = Str::studly('hello.world'); // 'HelloWorld'
$camel = Str::studly('aa-bb_cc.dd'); // 'AaBbCcDd'
```

##### ucfirst() - 首字母大写

[](#ucfirst---首字母大写)

```
$ucfirst = Str::ucfirst('hello'); // 'Hello'
```

##### lcfirst() - 首字母小写

[](#lcfirst---首字母小写)

```
$lcfirst = Str::lcfirst('Hello'); // 'hello'
```

##### ucwords() - 单词首字母大写

[](#ucwords---单词首字母大写)

```
$ucwords = Str::ucwords('hello world'); // 'Hello World'
```

##### upper() - 全部大写

[](#upper---全部大写)

```
$upper = Str::upper('hello'); // 'HELLO'
```

##### lower() - 全部小写

[](#lower---全部小写)

```
$lower = Str::lower('HELLO'); // 'hello'
```

##### swap() - 大小写转换

[](#swap---大小写转换)

```
$swap = Str::swap('Hello'); // 'hELLO'
```

##### title() - 标题格式

[](#title---标题格式)

```
$title = Str::title('hello world'); // 'Hello World'
```

#### 字符串查找和判断

[](#字符串查找和判断)

##### contains() - 是否包含子串

[](#contains---是否包含子串)

```
$contains = Str::contains('hello world', 'world'); // true
$contains = Str::contains('hello world', 'php'); // false
```

##### startsWith() - 是否以子串开头

[](#startswith---是否以子串开头)

```
$startsWith = Str::startsWith('hello world', 'hello'); // true
$startsWith = Str::startsWith('hello world', 'world'); // false
```

##### endsWith() - 是否以子串结尾

[](#endswith---是否以子串结尾)

```
$endsWith = Str::endsWith('hello world', 'world'); // true
$endsWith = Str::endsWith('hello world', 'hello'); // false
```

##### pos() - 子串首次出现位置

[](#pos---子串首次出现位置)

```
$pos = Str::pos('hello world', 'world'); // 6
$pos = Str::pos('hello world', 'php'); // false
```

##### rpos() - 子串最后一次出现位置

[](#rpos---子串最后一次出现位置)

```
$pos = Str::rpos('hello world world', 'world'); // 12
$pos = Str::rpos('hello world', 'php'); // false
```

##### count() - 子串出现次数

[](#count---子串出现次数)

```
$count = Str::count('hello world world', 'world'); // 2
```

##### match() - 字符串是否匹配正则

[](#match---字符串是否匹配正则)

```
$match = Str::match('hello123', '/^[a-z]+\d+$/'); // true
$match = Str::match('hello', '/^[a-z]+\d+$/'); // false
```

#### 字符串替换

[](#字符串替换)

##### replace() - 字符串替换

[](#replace---字符串替换)

```
$replaced = Str::replace('hello world', 'world', 'php'); // 'hello php'
```

##### replaceArray() - 字符串批量替换

[](#replacearray---字符串批量替换)

```
$replaced = Str::replaceArray('hello world', ['hello' => 'hi', 'world' => 'php']); // 'hi php'
```

##### replaceRegex() - 字符串正则替换

[](#replaceregex---字符串正则替换)

```
$replaced = Str::replaceRegex('hello123world', '/\d+/', '456'); // 'hello456world'
```

##### substrReplace() - 字符串截取并替换

[](#substrreplace---字符串截取并替换)

```
$replaced = Str::substrReplace('hello world', 'php', 6, 5); // 'hello php'
```

#### 字符串分割和连接

[](#字符串分割和连接)

##### split() - 字符串分割

[](#split---字符串分割)

```
$parts = Str::split('hello,world,php', ','); // ['hello', 'world', 'php']
```

##### toArray() - 字符串分割为数组

[](#toarray---字符串分割为数组)

```
$array = Str::toArray('hello,world,php', ','); // ['hello', 'world', 'php']
```

##### fromArray() - 数组连接为字符串

[](#fromarray---数组连接为字符串)

```
$string = Str::fromArray(['hello', 'world', 'php'], ','); // 'hello,world,php'
```

##### join() - 字符串连接

[](#join---字符串连接)

```
$joined = Str::join(['hello', 'world', 'php'], ','); // 'hello,world,php'
```

##### concat() - 字符串拼接

[](#concat---字符串拼接)

```
$concat = Str::concat('hello', ' ', 'world'); // 'hello world'
```

#### 字符串去除空白

[](#字符串去除空白)

##### trim() - 去除首尾空白

[](#trim---去除首尾空白)

```
$trimmed = Str::trim('  hello world  '); // 'hello world'
```

##### ltrim() - 去除左侧空白

[](#ltrim---去除左侧空白)

```
$ltrim = Str::ltrim('  hello world  '); // 'hello world  '
```

##### rtrim() - 去除右侧空白

[](#rtrim---去除右侧空白)

```
$rtrim = Str::rtrim('  hello world  '); // '  hello world'
```

##### clean() - 去除所有空白

[](#clean---去除所有空白)

```
$clean = Str::clean('  hello   world  '); // 'helloworld'
```

#### 字符串填充

[](#字符串填充)

##### padLeft() - 左侧填充

[](#padleft---左侧填充)

```
$padded = Str::padLeft('123', 6, '0'); // '000123'
```

##### padRight() - 右侧填充

[](#padright---右侧填充)

```
$padded = Str::padRight('123', 6, '0'); // '123000'
```

##### padBoth() - 两侧填充

[](#padboth---两侧填充)

```
$padded = Str::padBoth('123', 7, '*'); // '**123**'
```

#### 字符串重复

[](#字符串重复)

##### repeat() - 字符串重复

[](#repeat---字符串重复)

```
$repeated = Str::repeat('hello', 3); // 'hellohellohello'
```

##### reverse() - 字符串反转

[](#reverse---字符串反转)

```
$reversed = Str::reverse('hello'); // 'olleh'
```

#### 字符串随机

[](#字符串随机)

##### random() - 生成随机字符串

[](#random---生成随机字符串)

```
$random = Str::random(16); // 16位随机字符串
```

##### numeric() - 生成随机数字字符串

[](#numeric---生成随机数字字符串)

```
$numeric = Str::numeric(6); // 6位随机数字字符串
```

##### alpha() - 生成随机字母字符串

[](#alpha---生成随机字母字符串)

```
$alpha = Str::alpha(8); // 8位随机字母字符串
```

#### 字符串编码解码

[](#字符串编码解码)

##### toBase64() - Base64编码

[](#tobase64---base64编码)

```
$base64 = Str::toBase64('hello'); // 'aGVsbG8='
```

##### fromBase64() - Base64解码

[](#frombase64---base64解码)

```
$decoded = Str::fromBase64('aGVsbG8='); // 'hello'
```

##### toUrlEncode() - URL编码

[](#tourlencode---url编码)

```
$urlEncoded = Str::toUrlEncode('hello world'); // 'hello%20world'
```

##### fromUrlEncode() - URL解码

[](#fromurlencode---url解码)

```
$urlDecoded = Str::fromUrlEncode('hello%20world'); // 'hello world'
```

##### toHtmlEntities() - HTML实体编码

[](#tohtmlentities---html实体编码)

```
$htmlEncoded = Str::toHtmlEntities('hello'); // '&lt;div&gt;hello&lt;/div&gt;'
```

##### fromHtmlEntities() - HTML实体解码

[](#fromhtmlentities---html实体解码)

```
$htmlDecoded = Str::fromHtmlEntities('&lt;div&gt;hello&lt;/div&gt;'); // 'hello'
```

##### toJson() - JSON编码

[](#tojson---json编码)

```
$json = Str::toJson(['name' => '张三', 'age' => 25]); // '{"name":"张三","age":25}'
```

##### fromJson() - JSON解码

[](#fromjson---json解码)

```
$decoded = Str::fromJson('{"name":"张三","age":25}'); // ['name' => '张三', 'age' => 25]
```

##### toXml() - XML编码

[](#toxml---xml编码)

```
$xml = Str::toXml(['name' => '张三', 'age' => 25], 'root'); // '张三25'
```

##### fromXml() - XML解码

[](#fromxml---xml解码)

```
$decoded = Str::fromXml('张三25'); // ['name' => '张三', 'age' => 25]
```

##### toBinary() - 二进制编码

[](#tobinary---二进制编码)

```
$binary = Str::toBinary('hello'); // '0110100001100101011011000110110001101111'
```

##### fromBinary() - 二进制解码

[](#frombinary---二进制解码)

```
$decoded = Str::fromBinary('0110100001100101011011000110110001101111'); // 'hello'
```

##### toHex() - 十六进制编码

[](#tohex---十六进制编码)

```
$hex = Str::toHex('hello'); // '68656c6c6f'
```

##### fromHex() - 十六进制解码

[](#fromhex---十六进制解码)

```
$decoded = Str::fromHex('68656c6c6f'); // 'hello'
```

#### 字符串哈希

[](#字符串哈希)

##### md5() - MD5哈希

[](#md5---md5哈希)

```
$md5 = Str::md5('hello'); // '5d41402abc4b2a76b9719d911017c592'
```

##### sha1() - SHA1哈希

[](#sha1---sha1哈希)

```
$sha1 = Str::sha1('hello'); // 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
```

##### sha256() - SHA256哈希

[](#sha256---sha256哈希)

```
$sha256 = Str::sha256('hello'); // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
```

##### sha512() - SHA512哈希

[](#sha512---sha512哈希)

```
$sha512 = Str::sha512('hello'); // '9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043'
```

#### 字符串验证

[](#字符串验证)

##### isEmail() - 是否为邮箱

[](#isemail---是否为邮箱)

```
$isEmail = Str::isEmail('user@example.com'); // true
$isEmail = Str::isEmail('invalid-email'); // false
```

##### isUrl() - 是否为URL

[](#isurl---是否为url)

```
$isUrl = Str::isUrl('https://example.com'); // true
$isUrl = Str::isUrl('not-a-url'); // false
```

##### isIp() - 是否为IP地址

[](#isip---是否为ip地址)

```
$isIp = Str::isIp('192.168.1.1'); // true
$isIp = Str::isIp('not-an-ip'); // false
```

##### isIpv4() - 是否为IPv4地址

[](#isipv4---是否为ipv4地址)

```
$isIpv4 = Str::isIpv4('192.168.1.1'); // true
$isIpv4 = Str::isIpv4('2001:0db8:85a3:0000:0000:8a2e:0370:7334'); // false
```

##### isIpv6() - 是否为IPv6地址

[](#isipv6---是否为ipv6地址)

```
$isIpv6 = Str::isIpv6('2001:0db8:85a3:0000:0000:8a2e:0370:7334'); // true
$isIpv6 = Str::isIpv6('192.168.1.1'); // false
```

##### isPhone() - 是否为手机号

[](#isphone---是否为手机号)

```
$isPhone = Str::isPhone('13800138000'); // true
$isPhone = Str::isPhone('12345678901'); // false
```

##### isIdCard() - 是否为身份证号

[](#isidcard---是否为身份证号)

```
$isIdCard = Str::isIdCard('110101199001011234'); // true
$isIdCard = Str::isIdCard('123456789012345678'); // false
```

##### isBankCard() - 是否为银行卡号

[](#isbankcard---是否为银行卡号)

```
$isBankCard = Str::isBankCard('6222021234567890123'); // true
$isBankCard = Str::isBankCard('1234567890'); // false
```

##### isNumeric() - 是否为数字

[](#isnumeric---是否为数字)

```
$isNumeric = Str::isNumeric('12345'); // true
$isNumeric = Str::isNumeric('abc123'); // false
```

##### isAlpha() - 是否为字母

[](#isalpha---是否为字母)

```
$isAlpha = Str::isAlpha('hello'); // true
$isAlpha = Str::isAlpha('hello123'); // false
```

##### isAlnum() - 是否为字母数字

[](#isalnum---是否为字母数字)

```
$isAlnum = Str::isAlnum('hello123'); // true
$isAlnum = Str::isAlnum('hello world'); // false
```

##### isHex() - 是否为十六进制

[](#ishex---是否为十六进制)

```
$isHex = Str::isHex('1a2b3c'); // true
$isHex = Str::isHex('1g2h3i'); // false
```

##### isBinary() - 是否为二进制

[](#isbinary---是否为二进制)

```
$isBinary = Str::isBinary('01010101'); // true
$isBinary = Str::isBinary('12345678'); // false
```

##### isJson() - 是否为JSON

[](#isjson---是否为json)

```
$isJson = Str::isJson('{"name":"张三"}'); // true
$isJson = Str::isJson('not json'); // false
```

##### isXml() - 是否为XML

[](#isxml---是否为xml)

```
$isXml = Str::isXml('hello'); // true
$isXml = Str::isXml('not xml'); // false
```

##### isSerialized() - 是否为序列化数据

[](#isserialized---是否为序列化数据)

```
$isSerialized = Str::isSerialized('a:1:{i:0;s:5:"hello";}'); // true
$isSerialized = Str::isSerialized('not serialized'); // false
```

##### isBase64() - 是否为Base64

[](#isbase64---是否为base64)

```
$isBase64 = Str::isBase64('aGVsbG8='); // true
$isBase64 = Str::isBase64('not base64'); // false
```

#### 字符串转换

[](#字符串转换)

##### toArray() - 字符串转数组

[](#toarray---字符串转数组)

```
$array = Str::toArray('hello,world,php', ','); // ['hello', 'world', 'php']
```

##### fromArray() - 数组转字符串

[](#fromarray---数组转字符串)

```
$string = Str::fromArray(['hello', 'world', 'php'], ','); // 'hello,world,php'
```

##### toObject() - 字符串转对象

[](#toobject---字符串转对象)

```
$object = Str::toObject('{"name":"张三","age":25}'); // stdClass Object ( [name] => 张三 [age] => 25 )
```

##### fromObject() - 对象转字符串

[](#fromobject---对象转字符串)

```
$string = Str::fromObject((object)['name' => '张三', 'age' => 25]); // '{"name":"张三","age":25}'
```

##### toQuery() - 字符串转查询字符串

[](#toquery---字符串转查询字符串)

```
$query = Str::toQuery(['name' => '张三', 'age' => 25]); // 'name=%E5%BC%A0%E4%B8%89&age=25'
```

##### fromQuery() - 查询字符串转数组

[](#fromquery---查询字符串转数组)

```
$array = Str::fromQuery('name=%E5%BC%A0%E4%B8%89&age=25'); // ['name' => '张三', 'age' => 25]
```

#### 字符串格式化

[](#字符串格式化)

##### format() - 字符串格式化

[](#format---字符串格式化)

```
$formatted = Str::format('Hello, %s! You are %d years old.', '张三', 25); // 'Hello, 张三! You are 25 years old.'
```

##### template() - 字符串模板渲染

[](#template---字符串模板渲染)

```
$rendered = Str::template('Hello, {{name}}! Age: {{age}}', ['name' => '张三', 'age' => 25]); // 'Hello, 张三! Age: 25'
```

##### indent() - 字符串缩进

[](#indent---字符串缩进)

```
$indented = Str::indent('hello', 4); // '    hello'
```

##### unindent() - 字符串去除缩进

[](#unindent---字符串去除缩进)

```
$unindented = Str::unindent('    hello'); // 'hello'
```

#### 字符串字符操作

[](#字符串字符操作)

##### first() - 获取字符串首字符

[](#first---获取字符串首字符)

```
$first = Str::first('hello'); // 'h'
```

##### last() - 获取字符串尾字符

[](#last---获取字符串尾字符)

```
$last = Str::last('hello'); // 'o'
```

##### firstN() - 获取字符串前N个字符

[](#firstn---获取字符串前n个字符)

```
$firstN = Str::firstN('hello', 2); // 'he'
```

##### lastN() - 获取字符串后N个字符

[](#lastn---获取字符串后n个字符)

```
$lastN = Str::lastN('hello', 2); // 'lo'
```

##### removeFirst() - 去除首字符

[](#removefirst---去除首字符)

```
$removed = Str::removeFirst('hello'); // 'ello'
```

##### removeLast() - 去除尾字符

[](#removelast---去除尾字符)

```
$removed = Str::removeLast('hello'); // 'hell'
```

##### removeFirstN() - 去除前N个字符

[](#removefirstn---去除前n个字符)

```
$removed = Str::removeFirstN('hello', 2); // 'llo'
```

##### removeLastN() - 去除后N个字符

[](#removelastn---去除后n个字符)

```
$removed = Str::removeLastN('hello', 2); // 'hel'
```

#### 字符串统计

[](#字符串统计)

##### count() - 统计子串出现次数

[](#count---统计子串出现次数)

```
$count = Str::count('hello world world', 'world'); // 2
```

##### wordCount() - 统计单词数

[](#wordcount---统计单词数)

```
$wordCount = Str::wordCount('hello world php'); // 3
```

##### charCount() - 统计字符数

[](#charcount---统计字符数)

```
$charCount = Str::charCount('hello'); // 5
```

##### byteLength() - 统计字节长度

[](#bytelength---统计字节长度)

```
$byteLength = Str::byteLength('你好'); // 6（UTF-8编码）
```

#### 字符串安全

[](#字符串安全)

##### escapeHtml() - 转义HTML特殊字符

[](#escapehtml---转义html特殊字符)

```
$escaped = Str::escapeHtml('hello'); // '&lt;div&gt;hello&lt;/div&gt;'
```

##### escapeSql() - 转义SQL特殊字符

[](#escapesql---转义sql特殊字符)

```
$escaped = Str::escapeSql("O'Reilly"); // "O\'Reilly"
```

##### escapeJs() - 转义JavaScript特殊字符

[](#escapejs---转义javascript特殊字符)

```
$escaped = Str::escapeJs("It's a test"); // "It\'s a test"
```

##### escapeRegex() - 转义正则表达式特殊字符

[](#escaperegex---转义正则表达式特殊字符)

```
$escaped = Str::escapeRegex('hello.world'); // 'hello\.world'
```

#### 字符串比较

[](#字符串比较)

##### compare() - 字符串比较

[](#compare---字符串比较)

```
$compare = Str::compare('hello', 'hello'); // 0（相等）
$compare = Str::compare('hello', 'world'); // -15（不相等）
```

##### similarity() - 字符串相似度

[](#similarity---字符串相似度)

```
$similarity = Str::similarity('hello', 'hello'); // 1.0（完全相同）
$similarity = Str::similarity('hello', 'world'); // 0.2（相似度）
```

##### distance() - 字符串编辑距离

[](#distance---字符串编辑距离)

```
$distance = Str::distance('hello', 'hello'); // 0（相同）
$distance = Str::distance('hello', 'world'); // 4（编辑距离）
```

时间处理模块
------

[](#时间处理模块)

### 特性

[](#特性-2)

- ✅ 时间格式化
- ✅ 时间计算（加法、减法、差值）
- ✅ 常用时间获取（当前时间、今天、昨天、明天）
- ✅ 时区支持
- ✅ 人性化时间显示、日期范围计算

### 核心方法

[](#核心方法-2)

方法名功能描述调用示例[`format()`](#timeformat---%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%97%B6%E9%97%B4)格式化时间`Time::format(time(), 'Y-m-d')`[`now()`](#timenow---%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%B6%E9%97%B4)获取当前时间`Time::now()`[`today()`](#timetoday---%E8%8E%B7%E5%8F%96%E4%BB%8A%E5%A4%A9%E6%97%A5%E6%9C%9F)获取今天日期`Time::today()`[`yesterday()`](#timeyesterday---%E8%8E%B7%E5%8F%96%E6%98%A8%E5%A4%A9%E6%97%A5%E6%9C%9F)获取昨天日期`Time::yesterday()`[`tomorrow()`](#timetomorrow---%E8%8E%B7%E5%8F%96%E6%98%8E%E5%A4%A9%E6%97%A5%E6%9C%9F)获取明天日期`Time::tomorrow()`[`add()`](#timeadd---%E6%97%B6%E9%97%B4%E5%8A%A0%E6%B3%95)时间加法`Time::add(time(), 3600)`[`sub()`](#timesub---%E6%97%B6%E9%97%B4%E5%87%8F%E6%B3%95)时间减法`Time::sub(time(), 3600)`[`diff()`](#timediff---%E6%97%B6%E9%97%B4%E5%B7%AE)时间差`Time::diff(time(), time() - 3600)`[`diffForHumans()`](#timediffforhumans---%E4%BA%BA%E6%80%A7%E5%8C%96%E6%97%B6%E9%97%B4%E5%B7%AE)人性化时间差`Time::diffForHumans(time() - 3600)`[`weekStart()`](#timeweekstart---%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%91%A8%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)本周开始时间`Time::weekStart()`[`weekEnd()`](#timeweekend---%E8%8E%B7%E5%8F%96%E6%9C%AC%E5%91%A8%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)本周结束时间`Time::weekEnd()`[`monthStart()`](#timemonthstart---%E8%8E%B7%E5%8F%96%E6%9C%AC%E6%9C%88%E5%BC%80%E5%A7%8B%E6%97%B6%E9%97%B4)本月开始时间`Time::monthStart()`[`monthEnd()`](#timemonthend---%E8%8E%B7%E5%8F%96%E6%9C%AC%E6%9C%88%E7%BB%93%E6%9D%9F%E6%97%B6%E9%97%B4)本月结束时间`Time::monthEnd()`### 使用示例

[](#使用示例-2)

#### 时间格式化

[](#时间格式化)

##### format() - 格式化时间

[](#format---格式化时间)

```
$formatted = Time::format(time(), 'Y-m-d H:i:s'); // '2025-12-26 12:00:00'
$formatted = Time::format(time(), 'Y年m月d日'); // '2025年12月26日'
$formatted = Time::format(1735200000, 'Y-m-d'); // '2025-12-26'
```

##### now() - 获取当前时间

[](#now---获取当前时间)

```
$now = Time::now(); // '2025-12-26 12:00:00'
$now = Time::now('Y-m-d'); // '2025-12-26'
$now = Time::now('H:i:s'); // '12:00:00'
```

##### today() - 获取今天日期

[](#today---获取今天日期)

```
$today = Time::today(); // '2025-12-26'
$today = Time::today('Y-m-d H:i:s'); // '2025-12-26 00:00:00'
```

##### yesterday() - 获取昨天日期

[](#yesterday---获取昨天日期)

```
$yesterday = Time::yesterday(); // '2025-12-25'
$yesterday = Time::yesterday('Y-m-d H:i:s'); // '2025-12-25 00:00:00'
```

##### tomorrow() - 获取明天日期

[](#tomorrow---获取明天日期)

```
$tomorrow = Time::tomorrow(); // '2025-12-27'
$tomorrow = Time::tomorrow('Y-m-d H:i:s'); // '2025-12-27 00:00:00'
```

#### 时间计算

[](#时间计算)

```
$timestamp = time();
```

##### add() - 时间加法

[](#add---时间加法)

```
$newTime = Time::add($timestamp, 3600); // 加1小时
$newTime = Time::add($timestamp, 86400); // 加1天
$newTime = Time::add($timestamp, 604800); // 加1周
```

##### sub() - 时间减法

[](#sub---时间减法)

```
$newTime = Time::sub($timestamp, 3600); // 减1小时
$newTime = Time::sub($timestamp, 86400); // 减1天
$newTime = Time::sub($timestamp, 604800); // 减1周
```

##### diff() - 时间差

[](#diff---时间差)

```
$diff = Time::diff(time(), time() - 3600); // 3600（秒）
$diff = Time::diff(time() - 86400, time()); // 86400（秒）
```

##### diffForHumans() - 人性化时间差

[](#diffforhumans---人性化时间差)

```
$human = Time::diffForHumans(time() - 60); // '1分钟前'
$human = Time::diffForHumans(time() - 3600); // '1小时前'
$human = Time::diffForHumans(time() - 86400); // '1天前'
$human = Time::diffForHumans(time() - 2592000); // '1个月前'
$human = Time::diffForHumans(time() - 31536000); // '1年前'
$human = Time::diffForHumans(time() + 3600); // '1小时后'
$human = Time::diffForHumans(time() + 86400); // '1天后'
// 指定基准时间的人性化时间差
$human = Time::diffForHumans(time() - 3600, time() - 7200); // '1小时前'
```

#### 周日期范围

[](#周日期范围)

##### weekStart() - 获取本周开始时间

[](#weekstart---获取本周开始时间)

```
$weekStart = Time::weekStart(); // 本周一00:00:00的时间戳
$weekStart = Time::weekStart(time()); // 指定时间所在周的开始时间
$weekStartFormatted = Time::format(Time::weekStart(), 'Y-m-d H:i:s'); // '2025-12-22 00:00:00'
```

##### weekEnd() - 获取本周结束时间

[](#weekend---获取本周结束时间)

```
$weekEnd = Time::weekEnd(); // 本周日23:59:59的时间戳
$weekEnd = Time::weekEnd(time()); // 指定时间所在周的结束时间
$weekEndFormatted = Time::format(Time::weekEnd(), 'Y-m-d H:i:s'); // '2025-12-28 23:59:59'
```

##### lastWeekStart() - 获取上周开始时间

[](#lastweekstart---获取上周开始时间)

```
$lastWeekStart = Time::lastWeekStart(); // 上周一00:00:00的时间戳
$lastWeekStartFormatted = Time::format(Time::lastWeekStart(), 'Y-m-d H:i:s'); // '2025-12-15 00:00:00'
```

##### lastWeekEnd() - 获取上周结束时间

[](#lastweekend---获取上周结束时间)

```
$lastWeekEnd = Time::lastWeekEnd(); // 上周日23:59:59的时间戳
$lastWeekEndFormatted = Time::format(Time::lastWeekEnd(), 'Y-m-d H:i:s'); // '2025-12-21 23:59:59'
```

#### 月日期范围

[](#月日期范围)

##### monthStart() - 获取本月开始时间

[](#monthstart---获取本月开始时间)

```
$monthStart = Time::monthStart(); // 本月1日00:00:00的时间戳
$monthStart = Time::monthStart(time()); // 指定时间所在月的开始时间
$monthStartFormatted = Time::format(Time::monthStart(), 'Y-m-d H:i:s'); // '2025-12-01 00:00:00'
```

##### monthEnd() - 获取本月结束时间

[](#monthend---获取本月结束时间)

```
$monthEnd = Time::monthEnd(); // 本月最后一天23:59:59的时间戳
$monthEnd = Time::monthEnd(time()); // 指定时间所在月的结束时间
$monthEndFormatted = Time::format(Time::monthEnd(), 'Y-m-d H:i:s'); // '2025-12-31 23:59:59'
```

##### lastMonthStart() - 获取上月开始时间

[](#lastmonthstart---获取上月开始时间)

```
$lastMonthStart = Time::lastMonthStart(); // 上月1日00:00:00的时间戳
$lastMonthStartFormatted = Time::format(Time::lastMonthStart(), 'Y-m-d H:i:s'); // '2025-11-01 00:00:00'
```

##### lastMonthEnd() - 获取上月结束时间

[](#lastmonthend---获取上月结束时间)

```
$lastMonthEnd = Time::lastMonthEnd(); // 上月最后一天23:59:59的时间戳
$lastMonthEndFormatted = Time::format(Time::lastMonthEnd(), 'Y-m-d H:i:s'); // '2025-11-30 23:59:59'
```

#### 年日期范围

[](#年日期范围)

##### yearStart() - 获取本年开始时间

[](#yearstart---获取本年开始时间)

```
$yearStart = Time::yearStart(); // 本年1月1日00:00:00的时间戳
$yearStart = Time::yearStart(time()); // 指定时间所在年的开始时间
$yearStartFormatted = Time::format(Time::yearStart(), 'Y-m-d H:i:s'); // '2025-01-01 00:00:00'
```

##### yearEnd() - 获取本年结束时间

[](#yearend---获取本年结束时间)

```
$yearEnd = Time::yearEnd(); // 本年12月31日23:59:59的时间戳
$yearEnd = Time::yearEnd(time()); // 指定时间所在年的结束时间
$yearEndFormatted = Time::format(Time::yearEnd(), 'Y-m-d H:i:s'); // '2025-12-31 23:59:59'
```

##### lastYearStart() - 获取上年开始时间

[](#lastyearstart---获取上年开始时间)

```
$lastYearStart = Time::lastYearStart(); // 上年1月1日00:00:00的时间戳
$lastYearStartFormatted = Time::format(Time::lastYearStart(), 'Y-m-d H:i:s'); // '2024-01-01 00:00:00'
```

##### lastYearEnd() - 获取上年结束时间

[](#lastyearend---获取上年结束时间)

```
$lastYearEnd = Time::lastYearEnd(); // 上年12月31日23:59:59的时间戳
$lastYearEndFormatted = Time::format(Time::lastYearEnd(), 'Y-m-d H:i:s'); // '2024-12-31 23:59:59'
```

#### 时间判断

[](#时间判断)

```
$timestamp = time();
```

##### between() - 判断是否在某个时间区间内

[](#between---判断是否在某个时间区间内)

```
$inRange = Time::between($timestamp, time() - 3600, time() + 3600); // true
$inRange = Time::between(time() - 7200, time() - 3600, time()); // false
```

##### isToday() - 判断是否是今天

[](#istoday---判断是否是今天)

```
$isToday = Time::isToday($timestamp); // true
$isToday = Time::isToday(time() - 86400); // false
```

##### isYesterday() - 判断是否是昨天

[](#isyesterday---判断是否是昨天)

```
$isYesterday = Time::isYesterday(time() - 86400); // true
$isYesterday = Time::isYesterday(time()); // false
```

##### isTomorrow() - 判断是否是明天

[](#istomorrow---判断是否是明天)

```
$isTomorrow = Time::isTomorrow(time() + 86400); // true
$isTomorrow = Time::isTomorrow(time()); // false
```

##### isThisWeek() - 判断是否是本周

[](#isthisweek---判断是否是本周)

```
$isThisWeek = Time::isThisWeek($timestamp); // true
$isThisWeek = Time::isThisWeek(time() - 604800); // false
```

##### isThisMonth() - 判断是否是本月

[](#isthismonth---判断是否是本月)

```
$isThisMonth = Time::isThisMonth($timestamp); // true
$isThisMonth = Time::isThisMonth(strtotime('2025-11-01')); // false
```

##### isThisYear() - 判断是否是本年

[](#isthisyear---判断是否是本年)

```
$isThisYear = Time::isThisYear($timestamp); // true
$isThisYear = Time::isThisYear(strtotime('2024-01-01')); // false
```

#### 日期信息获取

[](#日期信息获取)

##### daysInMonth() - 获取某个月的天数

[](#daysinmonth---获取某个月的天数)

```
$days = Time::daysInMonth(12); // 31（12月有31天）
$days = Time::daysInMonth(2, 2024); // 29（2024年2月有29天，闰年）
$days = Time::daysInMonth(2, 2023); // 28（2023年2月有28天，平年）
```

##### dayOfWeek() - 获取某天是周几

[](#dayofweek---获取某天是周几)

```
$weekday = Time::dayOfWeek(time()); // 0-6（0表示周日，1表示周一，以此类推）
$weekday = Time::dayOfWeek(strtotime('2025-12-26')); // 5（周五）
```

##### dayOfWeekName() - 获取某天是周几（中文名称）

[](#dayofweekname---获取某天是周几中文名称)

```
$weekdayName = Time::dayOfWeekName(time()); // '周五'
$weekdayName = Time::dayOfWeekName(strtotime('2025-12-28')); // '周日'
```

##### dayOfYear() - 获取某天是本年第几天

[](#dayofyear---获取某天是本年第几天)

```
$dayOfYear = Time::dayOfYear(time()); // 360（2025年第360天）
$dayOfYear = Time::dayOfYear(strtotime('2025-01-01')); // 1（第1天）
```

##### weekOfYear() - 获取某天是本年第几周

[](#weekofyear---获取某天是本年第几周)

```
$weekOfYear = Time::weekOfYear(time()); // 52（第52周）
$weekOfYear = Time::weekOfYear(strtotime('2025-01-01')); // 1（第1周）
```

#### 年龄计算

[](#年龄计算)

##### age() - 计算年龄

[](#age---计算年龄)

```
$age = Time::age('1990-01-01'); // 35（假设当前是2025年）
$age = Time::age('2000-12-31'); // 24（假设当前是2025年）
$age = Time::age('2010-06-15'); // 15（假设当前是2025年）
```

#### 时间戳转换

[](#时间戳转换)

##### toTimestamp() - 时间字符串转时间戳

[](#totimestamp---时间字符串转时间戳)

```
$timestamp = Time::toTimestamp('2025-12-26 12:00:00'); // 1735200000
$timestamp = Time::toTimestamp('2025-12-26'); // 1735152000
$timestamp = Time::toTimestamp('now'); // 当前时间戳
$timestamp = Time::toTimestamp('+1 day'); // 明天同一时间的时间戳
```

##### toMillisecond() - 时间戳转毫秒

[](#tomillisecond---时间戳转毫秒)

```
$millisecond = Time::toMillisecond(time()); // 1735200000000
$millisecond = Time::toMillisecond(1735200000); // 1735200000000
```

##### fromMillisecond() - 毫秒转时间戳

[](#frommillisecond---毫秒转时间戳)

```
$timestamp = Time::fromMillisecond(1735200000000); // 1735200000
```

##### millisecond() - 获取当前毫秒时间戳

[](#millisecond---获取当前毫秒时间戳)

```
$millisecond = Time::millisecond(); // 当前时间的毫秒时间戳
```

##### microsecond() - 获取当前微秒时间戳

[](#microsecond---获取当前微秒时间戳)

```
$microsecond = Time::microsecond(); // 当前时间的微秒时间戳
```

##### microtime() - 获取当前时间戳（带微秒）

[](#microtime---获取当前时间戳带微秒)

```
$microtime = Time::microtime(); // 1735200000.123456
```

#### 时区操作

[](#时区操作)

##### timezone() - 获取当前时区

[](#timezone---获取当前时区)

```
$timezone = Time::timezone(); // 'Asia/Shanghai'（或其他时区）
```

##### setTimezone() - 设置时区

[](#settimezone---设置时区)

```
$success = Time::setTimezone('UTC'); // true
$success = Time::setTimezone('America/New_York'); // true

// 设置时区后获取时间
Time::setTimezone('UTC');
$utcTime = Time::now(); // UTC时间

Time::setTimezone('Asia/Shanghai');
$shanghaiTime = Time::now(); // 上海时间
```

### 实际应用场景

[](#实际应用场景)

```
// 订单创建时间显示
$createdAt = time() - 3600; // 1小时前创建
$displayTime = Time::diffForHumans($createdAt); // '1小时前'

// 数据统计时间范围
$weekStart = Time::weekStart();
$weekEnd = Time::weekEnd();
// 查询本周数据：WHERE created_at >= $weekStart AND created_at = $lastMonthStart AND created_at = $yearStart AND created_at = 1 && $weekday  3）
$result = Math::compare(3, 5); // -1（3 < 5）
$result = Math::compare(5, 5); // 0（相等）
```

##### equal() - 判断两个数是否相等

[](#equal---判断两个数是否相等)

```
$equal = Math::equal(0.1 + 0.2, 0.3); // true（解决浮点数比较问题）
$equal = Math::equal('1.000', '1.00', 2); // true（保留2位小数比较）
```

#### 格式化

[](#格式化)

##### format() - 格式化数字

[](#format---格式化数字)

```
$formatted = Math::format(1234567.89, 2, true); // 1,234,567.89（带千分位）
$formatted = Math::format(1234567.89, 2, false); // 1234567.89（不带千分位）
$formatted = Math::format('1234567.89123', 3, true); // 1,234,567.891
```

#### 三角函数

[](#三角函数)

##### sin() - 正弦函数

[](#sin---正弦函数)

```
$sin = Math::sin(Math::deg2rad(30)); // 0.5（30度的正弦值）
$sin = Math::sin(3.14159 / 2); // 1（π/2的正弦值）
```

##### cos() - 余弦函数

[](#cos---余弦函数)

```
$cos = Math::cos(Math::deg2rad(60)); // 0.5（60度的余弦值）
$cos = Math::cos(0); // 1（0度的余弦值）
```

##### tan() - 正切函数

[](#tan---正切函数)

```
$tan = Math::tan(Math::deg2rad(45)); // 1（45度的正切值）
$tan = Math::tan(3.14159 / 4); // 1（π/4的正切值）
```

##### asin() - 反正弦函数

[](#asin---反正弦函数)

```
$asin = Math::asin(1); // 1.5708（π/2）
$asin = Math::asin(0.5); // 0.5236（π/6）
```

##### acos() - 反余弦函数

[](#acos---反余弦函数)

```
$acos = Math::acos(0); // 1.5708（π/2）
$acos = Math::acos(0.5); // 1.0472（π/3）
```

##### atan() - 反正切函数

[](#atan---反正切函数)

```
$atan = Math::atan(1); // 0.7854（π/4）
$atan = Math::atan(0); // 0
```

#### 对数运算

[](#对数运算)

##### ln() - 自然对数（以e为底）

[](#ln---自然对数以e为底)

```
$ln = Math::ln(Math::exp(1)); // 1
$ln = Math::ln(2.71828); // 1
```

##### log10() - 常用对数（以10为底）

[](#log10---常用对数以10为底)

```
$log10 = Math::log10(100); // 2
$log10 = Math::log10(1000); // 3
```

##### log() - 自定义底数对数

[](#log---自定义底数对数)

```
$log = Math::log(8, 2); // 3（2的3次方等于8）
$log = Math::log(100, 10); // 2（10的2次方等于100）
```

#### 角度转换

[](#角度转换)

##### rad2deg() - 弧度转角度

[](#rad2deg---弧度转角度)

```
$deg = Math::rad2deg(3.14159); // 180（π弧度 = 180度）
$deg = Math::rad2deg(1.5708); // 90（π/2弧度 = 90度）
```

##### deg2rad() - 角度转弧度

[](#deg2rad---角度转弧度)

```
$rad = Math::deg2rad(180); // 3.14159（180度 = π弧度）
$rad = Math::deg2rad(90); // 1.5708（90度 = π/2弧度）
```

#### 数值操作

[](#数值操作)

##### abs() - 绝对值

[](#abs---绝对值)

```
$abs = Math::abs(-10); // 10
$abs = Math::abs(10); // 10
$abs = Math::abs('-5.5'); // 5.5
```

##### factorial() - 阶乘

[](#factorial---阶乘)

```
$factorial = Math::factorial(5); // 120（5! = 5×4×3×2×1）
$factorial = Math::factorial(0); // 1（0! = 1）
```

##### gcd() - 最大公约数

[](#gcd---最大公约数)

```
$gcd = Math::gcd(12, 18); // 6
$gcd = Math::gcd(24, 36); // 12
```

##### lcm() - 最小公倍数

[](#lcm---最小公倍数)

```
$lcm = Math::lcm(4, 6); // 12
$lcm = Math::lcm(3, 5); // 15
```

#### 金融计算

[](#金融计算)

##### percentage() - 百分比计算

[](#percentage---百分比计算)

```
$percentage = Math::percentage(25, 100); // 25（25占100的25%）
$percentage = Math::percentage('30', '150', 2); // 20.00
```

##### discount() - 折扣计算

[](#discount---折扣计算)

```
$discounted = Math::discount(100, 0.8); // 80（打8折）
$discounted = Math::discount('200', '0.7', 2); // 140.00（打7折）
```

##### tax() - 税费计算

[](#tax---税费计算)

```
$tax = Math::tax(100, 0.1); // 10（100的10%税额）
$tax = Math::tax('500', '0.13', 2); // 65.00（500的13%税额）
```

##### taxIncluded() - 含税金额计算

[](#taxincluded---含税金额计算)

```
$taxIncluded = Math::taxIncluded(100, 0.1); // 110（100 + 10%税）
$taxIncluded = Math::taxIncluded('500', '0.13', 2); // 565.00
```

##### taxExcluded() - 不含税金额计算

[](#taxexcluded---不含税金额计算)

```
$taxExcluded = Math::taxExcluded(110, 0.1); // 100（110 / 1.1）
$taxExcluded = Math::taxExcluded('565', '0.13', 2); // 500.00
```

##### simpleInterest() - 简单利息计算

[](#simpleinterest---简单利息计算)

```
$simpleInterest = Math::simpleInterest(1000, 0.05, 2); // 100（1000本金，5%年利率，2年）
$simpleInterest = Math::simpleInterest('5000', '0.04', 3, 2); // 600.00
```

##### compoundInterest() - 复利计算

[](#compoundinterest---复利计算)

```
$compoundInterest = Math::compoundInterest(1000, 0.05, 2); // 1102.5（1000本金，5%年利率，2年复利）
$compoundInterest = Math::compoundInterest('5000', '0.04', 3, 2); // 5624.32
```

#### 随机数生成

[](#随机数生成)

##### random() - 生成指定范围内的随机数

[](#random---生成指定范围内的随机数)

```
$random = Math::random(1, 100); // 1-100之间的随机整数
$random = Math::random('1.5', '5.5', 2); // 1.50-5.50之间的随机数（保留2位小数）
```

#### 范围检查

[](#范围检查)

##### inRange() - 数值范围检查

[](#inrange---数值范围检查)

```
$inRange = Math::inRange(5, 1, 10); // true（5在1-10范围内）
$inRange = Math::inRange(15, 1, 10); // false（15不在1-10范围内）
```

##### clamp() - 限制数值范围

[](#clamp---限制数值范围)

```
$clamped = Math::clamp(5, 1, 10); // 5（在范围内，保持不变）
$clamped = Math::clamp(15, 1, 10); // 10（超出最大值，限制为10）
$clamped = Math::clamp(-5, 1, 10); // 1（小于最小值，限制为1）
$clamped = Math::clamp('5.5', '1.0', '10.0', 1); // 5.5
```

#### 数值判断

[](#数值判断)

##### isPositive() - 判断是否为正数

[](#ispositive---判断是否为正数)

```
$isPositive = Math::isPositive(10); // true
$isPositive = Math::isPositive(-5); // false
$isPositive = Math::isPositive(0); // false
```

##### isNegative() - 判断是否为负数

[](#isnegative---判断是否为负数)

```
$isNegative = Math::isNegative(-5); // true
$isNegative = Math::isNegative(10); // false
$isNegative = Math::isNegative(0); // false
```

##### isZero() - 判断是否为零

[](#iszero---判断是否为零)

```
$isZero = Math::isZero(0); // true
$isZero = Math::isZero(0.0000000001, 10); // true（保留10位小数比较）
$isZero = Math::isZero(1); // false
```

##### isEven() - 判断是否为偶数

[](#iseven---判断是否为偶数)

```
$isEven = Math::isEven(4); // true
$isEven = Math::isEven(5); // false
```

##### isOdd() - 判断是否为奇数

[](#isodd---判断是否为奇数)

```
$isOdd = Math::isOdd(5); // true
$isOdd = Math::isOdd(4); // false
```

##### isPrime() - 判断是否为质数

[](#isprime---判断是否为质数)

```
$isPrime = Math::isPrime(7); // true
$isPrime = Math::isPrime(4); // false
$isPrime = Math::isPrime(2); // true
$isPrime = Math::isPrime(1); // false
```

##### isValid() - 判断数值是否有效

[](#isvalid---判断数值是否有效)

```
$isValid = Math::isValid(123); // true
$isValid = Math::isValid('123.45'); // true
$isValid = Math::isValid('abc'); // false
$isValid = Math::isValid(INF); // false（无穷大）
$isValid = Math::isValid(NAN); // false（非数字）
```

#### 插值运算

[](#插值运算)

##### lerp() - 线性插值

[](#lerp---线性插值)

```
$lerp = Math::lerp(0, 10, 0.5); // 5（0和10的中点）
$lerp = Math::lerp(0, 10, 0.25); // 2.5（0和10的25%位置）
$lerp = Math::lerp('0', '100', '0.75', 1); // 75.0
```

#### 统计分析

[](#统计分析)

##### average() - 平均值计算

[](#average---平均值计算)

```
$avg = Math::average([1, 2, 3, 4, 5]); // 3
$avg = Math::average([1.5, 2.5, 3.5], 2); // 2.50
```

##### median() - 中位数计算

[](#median---中位数计算)

```
$median = Math::median([1, 2, 3, 4, 5]); // 3
$median = Math::median([1, 2, 3, 4]); // 2.5（2和3的平均值）
$median = Math::median(['1.5', '2.5', '3.5'], 2); // 2.50
```

##### mode() - 众数计算

[](#mode---众数计算)

```
$mode = Math::mode([1, 2, 2, 3, 3, 3]); // 3（出现次数最多）
$mode = Math::mode([1, 2, 3]); // 1（多个众数时返回第一个）
```

##### standardDeviation() - 标准差计算

[](#standarddeviation---标准差计算)

```
$stdDev = Math::standardDeviation([1, 2, 3, 4, 5]); // 1.414
$stdDev = Math::standardDeviation([10, 20, 30], 2); // 10.00
```

### 实际应用场景

[](#实际应用场景-1)

```
// 电商订单金额计算
$subtotal = Math::add('99.99', '49.99'); // 149.98（商品小计）
$discount = Math::discount($subtotal, '0.9'); // 134.98（打9折）
$tax = Math::tax($discount, '0.13'); // 17.55（13%税）
$total = Math::add($discount, $tax, 2); // 152.53（总金额）

// 贷款利息计算
$principal = 100000; // 本金10万
$rate = 0.05; // 年利率5%
$years = 5; // 5年
$simpleInterest = Math::simpleInterest($principal, $rate, $years); // 25000（简单利息）
$compoundInterest = Math::compoundInterest($principal, $rate, $years); // 27628.16（复利）

// 数据分析
$scores = [85, 92, 78, 90, 88, 95, 82];
$avg = Math::average($scores, 2); // 87.14（平均分）
$median = Math::median($scores, 2); // 88.00（中位数）
$stdDev = Math::standardDeviation($scores, 2); // 5.67（标准差）

// 价格范围检查
$price = 99.99;
$minPrice = 50;
$maxPrice = 100;
if (Math::inRange($price, $minPrice, $maxPrice)) {
    echo '价格在合理范围内';
}

// 数值格式化显示
$amount = 1234567.89123;
$formatted = Math::format($amount, 2, true); // 1,234,567.89
```

地理位置处理模块
--------

[](#地理位置处理模块)

### 特性

[](#特性-4)

- ✅ 使用Haversine公式计算距离
- ✅ 支持多种距离单位（公里、英里、米）
- ✅ 支持方位角和中点计算

### 核心方法

[](#核心方法-4)

方法名功能描述调用示例[`distance()`](#geodistance---%E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E5%9D%90%E6%A0%87%E4%B9%8B%E9%97%B4%E7%9A%84%E8%B7%9D%E7%A6%BB)计算两点距离`Geo::distance(39.9042, 116.4074, 31.2304, 121.4737)`[`isValid()`](#geoisValid---%E5%9D%90%E6%A0%87%E9%AA%8C%E8%AF%81)验证坐标`Geo::isValid(39.9042, 116.4074)`[`bearing()`](#geobearing---%E8%AE%A1%E7%AE%97%E6%96%B9%E4%BD%8D%E8%A7%92)计算方位角`Geo::bearing(39.9042, 116.4074, 31.2304, 121.4737)`[`midpoint()`](#geomidpoint---%E8%AE%A1%E7%AE%97%E4%B8%AD%E7%82%B9%E5%9D%90%E6%A0%87)计算中点坐标`Geo::midpoint(39.9042, 116.4074, 31.2304, 121.4737)`### 使用示例

[](#使用示例-4)

##### distance() - 计算两个坐标之间的距离

[](#distance---计算两个坐标之间的距离)

```
$distance = Geo::distance(39.9042, 116.4074, 31.2304, 121.4737, 'km'); // 北京到上海的距离，约1067公里
```

##### isValid() - 坐标验证

[](#isvalid---坐标验证)

```
$valid = Geo::isValidCoordinate(39.9042, 116.4074); // true
```

##### midpoint() - 计算两个坐标之间的中点

[](#midpoint---计算两个坐标之间的中点)

```
$midpoint = Geo::midpoint(39.9042, 116.4074, 31.2304, 121.4737); // [35.593729492520936,119.07801023725797]
```

##### bearing() - 计算两个坐标之间的方位角

[](#bearing---计算两个坐标之间的方位角)

```
$bearing = Geo::bearing(39.9042, 116.4074, 31.2304, 121.4737); // 153.0726752205012
```

##### toRadians() - 将角度转换为弧度

[](#toradians---将角度转换为弧度)

```
$bearing = Geo::toRadians(90); // 1.5707963267948966
```

##### toDegrees() - 将弧度转换为角度

[](#todegrees---将弧度转换为角度)

```
$bearing = Geo::toDegrees(1.5707963267948966); // 90
```

##### toDMS() - 将十进制度数转换为度分秒（DMS）

[](#todms---将十进制度数转换为度分秒dms)

```
$bearing = Geo::toDMS(90, true); // [90,0,0,"N"]
$bearing = Geo::toDMS(90, false); // [90,0,0,"E"]
```

##### toDecimal() - 将度分秒（DMS）转换为十进制度数

[](#todecimal---将度分秒dms转换为十进制度数)

```
$bearing = Geo::toDecimal(90,0,0,"N"); // 90
```

##### gcj02ToBd09() - GCJ02坐标转BD09坐标

[](#gcj02tobd09---gcj02坐标转bd09坐标)

```
$bd01 = Geo::gcj02ToBd09(39.9042, 116.4074); // [39.9105, 116.4138]
```

##### bd09ToGcj02() - BD09坐标转GCJ02坐标

[](#bd09togcj02---bd09坐标转gcj02坐标)

```
$gcj01 = Geo::bd09ToGcj02(39.9105, 116.4138); // [39.9042, 116.4074]
```

##### wgs84ToGcj02() - WGS84坐标转GCJ02坐标（中国火星坐标系）

[](#wgs84togcj02---wgs84坐标转gcj02坐标中国火星坐标系)

```
$gcj02 = Geo::wgs84ToGcj02(39.9042, 116.4074); // [39.9056, 116.4136]
```

##### gcj02ToWgs84() - GCJ02坐标转WGS84坐标

[](#gcj02towgs84---gcj02坐标转wgs84坐标)

```
$wgs01 = Geo::gcj02ToWgs84(39.9056, 116.4136); // [39.9042, 116.4074]
```

##### wgs84ToBd09() - WGS84坐标转BD09坐标

[](#wgs84tobd09---wgs84坐标转bd09坐标)

```
$bd02 = Geo::wgs84ToBd09(39.9042, 116.4074); // [39.9119, 116.4200]
```

##### bd09ToWgs84() - BD09坐标转WGS84坐标

[](#bd09towgs84---bd09坐标转wgs84坐标)

```
$wgs02 = Geo::bd09ToWgs84(39.9119, 116.4200); // [39.9042, 116.4074]
```

IP地址处理模块
--------

[](#ip地址处理模块)

### 特性

[](#特性-5)

- ✅ 获取IP地址版本
- ✅ 验证IP地址格式
- ✅ 获取IP地址位置信息

### 核心方法

[](#核心方法-5)

方法名功能描述调用示例`getLocation()`获取IP地址位置信息`Ip::getLocation(192.168.10.88)``isValid()`验证IP地址格式`Ip::isValid(192.168.10.88)``isPrivate()`检查IP地址是否为私有/内部地址`Ip::isPrivate(192.168.10.88)``getVersion()`获取IP地址版本`Ip::getVersion(192.168.10.88)`### 使用示例

[](#使用示例-5)

##### getRealIp() - 获取真实客户端IP地址

[](#getrealip---获取真实客户端ip地址)

```
$ip = Ip::getRealIp();
```

##### isValid() - 验证IP地址格式是否有效

[](#isvalid---验证ip地址格式是否有效)

```
$valid = Ip::isValid('192.168.1.1'); // true
```

##### isPrivate() - 检查IP地址是否为私有/内部地址

[](#isprivate---检查ip地址是否为私有内部地址)

```
$private = Ip::isPrivate('192.168.1.1'); // true
```

##### getVersion() - 获取IP地址版本

[](#getversion---获取ip地址版本)

```
$ip = Ip::isPrivate();
```

##### toLong() - 将IP地址转换为长整数

[](#tolong---将ip地址转换为长整数)

```
$long = Ip::toLong('192.168.1.1'); // 3232235777
```

##### fromLong() - 将长整数转换为IP地址

[](#fromlong---将长整数转换为ip地址)

```
$ipStr = Ip::toString(3232235777); // '192.168.1.1'
```

##### getLocation() - 获取IP地址位置信息

[](#getlocation---获取ip地址位置信息)

```
$local = Ip::getLocation('192.168.1.1');
```

##### isFromCountry() - 检查IP地址是否来自特定国家

[](#isfromcountry---检查ip地址是否来自特定国家)

```
$ip = Ip::isFromCountry('192.168.1.1', 'CN');
```

##### getType() - 获取IP地址类型

[](#gettype---获取ip地址类型)

```
$type = Ip::getType('192.168.1.1');
```

代码生成模块
------

[](#代码生成模块)

### 特性

[](#特性-6)

- ✅ UUID生成
- ✅ 订单号生成（时间戳+随机数）
- ✅ 邀请码生成（自定义长度和字符集）
- ✅ URL安全码生成（Base64URL编码）
- ✅ 注册码生成（支持分段显示）
- ✅ 线程安全的随机数生成（random\_int）

### 核心方法

[](#核心方法-6)

方法名功能描述调用示例`uuid()`生成UUID`Crypto::uuid()``orderNo()`生成订单号`Crypto::orderNo('')``inviteCode()`生成邀请码`Crypto::inviteCode(6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')``urlSafeCode()`生成URL安全码`Crypto::urlSafeCode(16)``registerCode()`生成注册码`Crypto::registerCode(16, 4, '-')`### 使用示例

[](#使用示例-6)

##### uuid() - 生成uuid

[](#uuid---生成uuid)

```
$uuid = Generate::uuid();
```

##### orderNo() - 生成订单号

[](#orderno---生成订单号)

```
// 生成不带前缀的订单号
$orderNo = Generate::orderNo(); // 202512251200001234

// 生成带前缀的订单号
$orderNo = Generate::orderNo('ORD'); // ORD202507261234561234
```

##### inviteCode() - 生成邀请码

[](#invitecode---生成邀请码)

```
$inviteCode = Generate::inviteCode(8); // 8位邀请码
```

##### urlSafeCode() - 生成URL安全码

[](#urlsafecode---生成url安全码)

```
$urlSafe = Generate::urlSafeCode(16); // URL安全的随机码
```

##### registerCode() - 生成注册码

[](#registercode---生成注册码)

```
$registerCode = Generate::registerCode(12, 4); // 12位注册码，每4位分隔
```

加解密处理模块
-------

[](#加解密处理模块)

### 特性

[](#特性-7)

- ✅ MD5加密（支持加盐）
- ✅ 密码哈希（基于PHP原生password\_hash）
- ✅ SSL对称加密（AES-256-GCM）
- ✅ HMAC签名（支持多种算法）
- ✅ 双模式调用：实例调用 + 静态调用
- ✅ 符合安全最佳实践
- ✅ PHP8.3+只读属性确保配置安全

### 核心方法

[](#核心方法-7)

方法名功能描述调用示例`md5()`MD5加密（支持加盐）`Crypto::md5('123456', 'salt')``passwordHash()`密码哈希`Crypto::passwordHash('123456')``passwordVerify()`密码验证`Crypto::passwordVerify('123456', $hash)``sslEncrypt()`SSL对称加密`Crypto::sslEncrypt('data', $key)``sslDecrypt()`SSL对称解密`Crypto::sslDecrypt($encrypted, $key)`### 使用示例

[](#使用示例-7)

##### Crypto - 加密引擎说明

[](#crypto---加密引擎说明)

```
use Cdyun\PhpTool\Crypto;

// Sodium引擎 - 推荐使用（性能更高，安全性更强）
// 需要PHP扩展：sodium
$crypto = new Crypto('your_key', Crypto::ENGINE_SODIUM);

// OpenSSL引擎 - 通用选择
// 需要PHP扩展：openssl
$crypto = new Crypto('your_key', Crypto::ENGINE_OPENSSL);

// 自动选择引擎 - 自动选择最优引擎
$crypto = new Crypto('your_key', Crypto::ENGINE_AUTO);
```

##### Crypto - 加密模式说明

[](#crypto---加密模式说明)

```
use Cdyun\PhpTool\Crypto;

// 标准模式 - Base64编码
$crypto = new Crypto('your_key', Crypto::ENGINE_AUTO, Crypto::MODE_STANDARD);
$encrypted = $crypto->encrypt('敏感数据');
// 输出示例: VEhJUz1mYWxzZVZlcnNpb249MS4wJmtleT1zZWN1cmVfazEyMw==

// URL安全模式 - Base64URL编码（无=号，适合URL传输）
$crypto = new Crypto('your_key', Crypto::ENGINE_AUTO, Crypto::MODE_URL_SAFE);
$encrypted = $crypto->encrypt('敏感数据');
// 输出示例: VEhJUz1mYWxzZVZlcnNpb249MS4wJmtleT1zZWN1cmVfazEyMw

// 紧凑模式 - 十六进制编码（最短长度，适合存储）
$crypto = new Crypto('your_key', Crypto::ENGINE_AUTO, Crypto::MODE_COMPACT);
$encrypted = $crypto->encrypt('敏感数据');
// 输出示例: 54484349533b66756c73652076657273696f6e20312e302e303b6b65793d7365637572655f6b313233
```

##### Crypto - 基础加解密

[](#crypto---基础加解密)

```
use Cdyun\PhpTool\Crypto;

// 创建加密实例
$crypto = new Crypto('your_secret_key_2025');

// 加密数据
$encrypted = $crypto->encrypt('这是需要加密的敏感数据');
echo $encrypted;
// 输出示例: VEhJUz1mYWxzZVZlcnNpb249MS4wJmtleT1zZWN1cmVfazEyMw==

// 解密数据
$decrypted = $crypto->decrypt($encrypted);
echo $decrypted;
// 输出: 这是需要加密的敏感数据

// 使用不同的密钥
$crypto2 = new Crypto('another_key');
$encrypted2 = $crypto2->encrypt('另一个敏感数据');

// 解密（需要使用相同的密钥）
$decrypted2 = $crypto2->decrypt($encrypted2);
```

##### Crypto - 静态方法调用

[](#crypto---静态方法调用)

```
use Cdyun\PhpTool\Crypto;

// 静态加密（使用默认密钥）
$encrypted = Crypto::encrypt('敏感数据');
$decrypted = Crypto::decrypt($encrypted);

// 使用自定义密钥的静态方法
$encrypted = (new Crypto('custom_key'))->encrypt('敏感数据');
$decrypted = (new Crypto('custom_key'))->decrypt($encrypted);
```

##### md5() - MD5加密（支持加盐）

[](#md5---md5加密支持加盐)

```
// 基础MD5加密
$md5 = Crypto::md5('123456'); // e10adc3949ba59abbe56e057f20f883e

// 加盐MD5加密
$salt = 'your_custom_salt';
$md5WithSalt = Crypto::md5('123456', $salt); // 52c69e3a57331081823331c4e6999d23

// 多次加盐（提高安全性）
$doubleSalt = Crypto::md5(Crypto::md5('123456'), $salt);
```

##### passwordHash() - 密码哈希

[](#passwordhash----密码哈希)

```
$password = 'my_secure_password';
$hash = Crypto::passwordHash($password);
```

##### passwordVerify() - 密码哈希验证

[](#passwordverify----密码哈希验证)

```
// 密码正确
$isValid = Crypto::passwordVerify('my_secure_password', $hash);

// 密码错误
$isValid = Crypto::passwordVerify('wrong_password', $hash);

// 密码哈希更新（重新哈希）
if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
    $newHash = Crypto::passwordHash($password);
}
```

##### Crypto - HMAC签名

[](#crypto---hmac签名)

```
use Cdyun\PhpTool\Crypto\Crypto;

// SHA256签名（默认）
$signature = Crypto::hmac('待签名数据', 'your_secret_key');
echo $signature;
// 输出示例: 3a6eb0790f39ac87c94f3856b2dd2c5d110e0f9b0e9c9d6e7b8c9d0e1f2a3b4c

// SHA512签名
$signature512 = Crypto::hmac('待签名数据', 'your_secret_key', 'sha512');
echo $signature512;
// 输出示例: a4e6b8c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2

// MD5签名
$signatureMd5 = Crypto::hmac('待签名数据', 'your_secret_key', 'md5');
echo $signatureMd5;
// 输出示例: 1a1dc06f7a0b2c8d9e0f1a2b3c4d5e6f7

// 数据完整性验证
$originalData = '订单数据';
$originalSignature = Crypto::hmac($originalData, 'api_secret');

$receivedData = '订单数据';
$receivedSignature = $_SERVER['HTTP_SIGNATURE'] ?? '';

if (hash_equals($originalSignature, $receivedSignature)) {
    echo '数据完整性验证通过';
} else {
    echo '数据可能被篡改';
}
```

##### Crypto - SSL对称加解密

[](#crypto---ssl对称加解密)

```
use Cdyun\PhpTool\Crypto;

// 使用自定义密钥进行SSL加密
$key = 'your_ssl_key_32_bytes_long!';
$crypto = new Crypto();

$encrypted = $crypto->sslEncrypt('SSL加密数据', $key);
echo $encrypted;
// 输出示例: VGhpc0lzU1NMY0VuY3J5cHRlZERhdGE=

$decrypted = $crypto->sslDecrypt($encrypted, $key);
echo $decrypted;
// 输出: SSL加密数据
```

##### Crypto - 错误处理

[](#crypto---错误处理)

```
use Cdyun\PhpTool\Crypto;

$crypto = new Crypto('your_key');

try {
    $encrypted = $crypto->encrypt('敏感数据');
    $decrypted = $crypto->decrypt($encrypted);
    echo '加解密成功: ' . $decrypted;
} catch (\Exception $e) {
    echo '加解密失败: ' . $e->getMessage();
}

// 密钥错误时的解密异常
try {
    $wrongCrypto = new Crypto('wrong_key');
    $decrypted = $wrongCrypto->decrypt($encrypted);
} catch (\Exception $e) {
    echo '解密失败（密钥错误）: ' . $e->getMessage();
}
```

### 使用场景

[](#使用场景)

```
use Cdyun\PhpTool\Crypto;

// 场景1：用户敏感信息加密存储
function saveUserSensitiveData(Crypto $crypto, array $data): array
{
    return [
        'id' => $data['id'],
        'name' => $data['name'],
        'encrypted_phone' => $crypto->encrypt($data['phone']),
        'encrypted_id_card' => $crypto->encrypt($data['id_card'])
    ];
}

function getUserSensitiveData(Crypto $crypto, array $userData): array
{
    return [
        'id' => $userData['id'],
        'name' => $userData['name'],
        'phone' => $crypto->decrypt($userData['encrypted_phone']),
        'id_card' => $crypto->decrypt($userData['encrypted_id_card'])
    ];
}

// 场景2：API请求签名验证
function verifyApiRequest(Crypto $crypto, array $params, string $signature): bool
{
    $expectedSignature = Crypto::hmac(json_encode($params), $apiSecret);
    return hash_equals($expectedSignature, $signature);
}

// 场景3：密码安全存储
function registerUser(string $password): string
{
    return Crypto::passwordHash($password);
}

function verifyUserPassword(string $password, string $hash): bool
{
    return Crypto::passwordVerify($password, $hash);
}
```

HTTP请求处理模块
----------

[](#http请求处理模块)

### 特性

[](#特性-8)

- ✅ 支持HTTP/HTTPS协议
- ✅ 支持请求超时设置
- ✅ 支持请求头设置
- ✅ 支持请求参数设置
- ✅ 支持响应状态码、响应头、响应体获取
- ✅ 支持异常处理
- ✅ 支持多种HTTP方法（GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONS）
- ✅ 支持多种内容类型（JSON/form/multipart）
- ✅ 灵活的请求选项配置
- ✅ 响应处理和错误处理

### 核心方法

[](#核心方法-8)

方法名功能描述调用示例`get()`GET请求`Curl::get('https://api.example.com', $data)``post()`POST请求`Curl::post('https://api.example.com', $data)``put()`PUT请求`Curl::put('https://api.example.com/1', $data)``delete()`DELETE请求`Curl::delete('https://api.example.com/1')``head()`HEAD请求`Curl::head('https://api.example.com')``options()`OPTIONS请求`Curl::options('https://api.example.com')`### 使用示例

[](#使用示例-8)

##### setDefaultOptions() - 设置默认配置

[](#setdefaultoptions---设置默认配置)

```
Curl::setDefaultOptions([
        'timeout' => 60,
        'connect_timeout' => 20,
    ])
```

##### getDefaultOptions() - 获取默认配置

[](#getdefaultoptions---获取默认配置)

```
Curl::getDefaultOptions()
// 返回默认配置
//  [
//        'timeout' => 60,
//        'connect_timeout' => 20,
//        'verify' => true,
//  ]
```

##### reset() - 重置客户端实例

[](#reset---重置客户端实例)

```
Curl::reset()
```

##### options() - OPTIONS请求

[](#options---options请求)

```
$response = Curl::options('https://api.example.com', [], []);
```

##### head() - HEAD请求

[](#head---head请求)

```
$response = Curl::head('https://api.example.com', [], [], []);
```

##### get() - GET请求

[](#get---get请求)

```
$response = Curl::get('https://api.example.com', [], [], []);

$response = Curl::get('https://api.example.com/users', ['page' => 1, 'limit' => 10]);
```

##### post() - POST请求

[](#post---post请求)

```
$response = Curl::post('https://api.example.com', [], [], []);

$response = Curl::post('https://api.example.com', ['name' => 'John', 'email' => 'john@example.com']);
```

##### postForm() - POST表单请求

[](#postform---post表单请求)

```
$response = Curl::postForm('https://api.example.com', [], [], []);

$response = Curl::postForm('https://api.example.com', ['name' => 'John', 'email' => 'john@example.com']);
```

##### postMultipart() - POST文件上传请求

[](#postmultipart---post文件上传请求)

```
$response = Curl::postMultipart(
    'https://api.example.com/upload',
    [
        ['name' => 'file', 'contents' => fopen('/path/to/file.jpg', 'r')]
    ]
);
```

##### put() - PUT请求

[](#put---put请求)

```
$response = Curl::put('https://api.example.com/users/1', [], [], []);

$response = Curl::put('https://api.example.com/users/1', ['name' => 'Updated Name']);
```

##### putForm() - PUT表单请求

[](#putform---put表单请求)

```
$response = Curl::put('https://api.example.com/users/1', [], [], []);

$response = Curl::put('https://api.example.com/users/1', ['name' => 'Updated Name']);
```

##### delete() - PUT请求

[](#delete---put请求)

```
$response = Curl::delete('https://api.example.com/users/1', [], [], []);

$response = Curl::delete('https://api.example.com/users/1');
```

##### patch() - PATCH请求

[](#patch---patch请求)

```
$response = Curl::patch('https://api.example.com/users/1', [], [], []);

$response = Curl::patch('https://api.example.com/users/1', [
    'status' => 'active'
]);
```

目录文件处理
------

[](#目录文件处理)

### 使用示例

[](#使用示例-9)

##### scanFolder() - 搜索指定路径下的【直系】文件夹

[](#scanfolder---搜索指定路径下的直系文件夹)

```
$list = Dir::scanFolder($path);
```

##### getFileContent() - 获取文件内容

[](#getfilecontent---获取文件内容)

```
$content = Dir::getFileContent($path, $fileName);
```

##### listFileContent() - 获取指定路径文件夹下所有直系文件夹中所有指定文件名的php文件内容

[](#listfilecontent---获取指定路径文件夹下所有直系文件夹中所有指定文件名的php文件内容)

```
$list = Dir::listFileContent($path, $fileName);
```

##### deleteDirFile() - 清除指定文件夹下文件

[](#deletedirfile---清除指定文件夹下文件)

```
$list = Dir::deleteDirFile($dir_name);
```

##### scanFile() - 搜索文件夹下全部文件，指定扩展名，暂时不支持中文文件名

[](#scanfile---搜索文件夹下全部文件指定扩展名暂时不支持中文文件名)

```
$list = Dir::scanFile($path, $ext);
```

##### scanFileTree() - 搜索文件夹下全部文件返回树形结构，指定扩展名，暂时不支持中文文件名

[](#scanfiletree---搜索文件夹下全部文件返回树形结构指定扩展名暂时不支持中文文件名)

```
$list = Dir::scanFileTree($path, $prefix, $ext);
```

版本要求
====

[](#版本要求)

- PHP &gt;= 8.1
- ext-openssl
- ext-json

许可证
===

[](#许可证)

MIT License

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance84

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

16

Last Release

82d ago

Major Versions

v1.1.1 → v2.0.02026-02-23

PHP version history (2 changes)v1.0.1PHP ^8.1

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/743ffd5ad49f71554f068efde387da76b1a14f3cfd608928fc6c881d3dd22dfb?d=identicon)[clrainy](/maintainers/clrainy)

---

Top Contributors

[![cdyun303](https://avatars.githubusercontent.com/u/146640329?v=4)](https://github.com/cdyun303 "cdyun303 (20 commits)")

---

Tags

messagephphelperarraystringcurlcryptotimeIPtreetoolsgeocdyun

### Embed Badge

![Health badge](/badges/cdyun-php-tool/health.svg)

```
[![Health](https://phpackages.com/badges/cdyun-php-tool/health.svg)](https://phpackages.com/packages/cdyun-php-tool)
```

###  Alternatives

[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8311.6M36](/packages/jbzoo-utils)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34216.9k2](/packages/onesignal-onesignal-php-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
