PHPackages                             asuratu/utils - 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. asuratu/utils

ActiveLibrary

asuratu/utils
=============

工具助手

0.2.7(5y ago)05MITPHP

Since May 27Pushed 5y agoCompare

[ Source](https://github.com/asuratu/Utils)[ Packagist](https://packagist.org/packages/asuratu/utils)[ RSS](/packages/asuratu-utils/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (11)Used By (0)

实用工具包
=====

[](#实用工具包)

安装
==

[](#安装)

```
composer require jsyqw/utils

```

数组助手类 ArrayHelper
-----------------

[](#数组助手类-arrayhelper)

```
//把对象或者数组对象，转成数组
ArrayHelper::toArray($object, $properties = [], $recursive = true);

//获取对象或者数组的指定的值
ArrayHelper::getValue($array, $key, $default = null);

//根据指定的key，建立key对应索引的数组，或者分组后的索引数组
ArrayHelper::index($array, $key, $groups = []);

//把数组转成 key-value 的形式
ArrayHelper::map($array, $from, $to, $group = null);

//检查数组是否是列索引
ArrayHelper::isAssoc($array);

```

FileHelper
----------

[](#filehelper)

```
//把文件大小格式化成友好格式
FileHelper::format($bytes, $decimals = 2);

//删除文件 和 目录
FileHelper::delDir($path, $isDelCurrent = false);

//获取文件扩展
FileHelper::getExt($str);
```

IPHelper
--------

[](#iphelper)

```
//获取客户端真实ip
IPHelper::remoteIp($useProxy = false)

//随机生成 chinese`ip （爬虫伪造ip）
IPHelper::randIp()
```

StrHelper
---------

[](#strhelper)

```
//生成唯一数字 eg: YYYYMMDDHHIISSNNNNNNNNCC 24
StrHelper::uniqueNum();

//生成短的唯一码，可以根据编码的值推算出来年、月、日
//短唯一码的起始年份，默认是2020年
//【A:对应年】+【6：月16进制】+【04:日期】+【57112：时间戳后五位】+【46633：毫秒5位】+【随机两位】
//注意：
//1.如果年份年份大于24年，则对第一个字符倍增操作，比如我们程序运行到2047年的时候 则以 AA 开头，
//2.如果传入的起始年份大于当前年份，则返回的字符串前面增加“-”符号
StrHelper::shortUniqueStr();

//生成唯一的 guid
StrHelper::guid();

//随机字长度的随机字符串
StrHelper::random($length = 6, $type = 'string')
```

ValidateHelper
--------------

[](#validatehelper)

```
//验证手机号
ValidateHelper::checkPhone($phone);

//验证邮箱
ValidateHelper::checkEmail($email);

//验证是不是http开头的地址
ValidateHelper::isHttp($str);

//验证是否是 json 字符串
ValidateHelper::isJson($str)
```

HttpHelper
----------

[](#httphelper)

```
//curl post 请求封装
HttpHelper::curlPost($url, $data, $options = [])

//curl get 请求封装
HttpHelper::curlGet($url, $data, $options = [])

//curl 请求封装
HttpHelper::curl($method, $url, $data='', $options = [])

//curl post 异步请求不需要返回结果
HttpHelper::asyncCurlPost($url, $data, $options = [])

//curl get 异步请求不需要返回结果
HttpHelper::asyncGet($url, $data, $options = [])
```

RuntimeHelper
-------------

[](#runtimehelper)

```
// 启动计时
RuntimeHelper::instance()->start();

//结束计时并返回消耗的时间（单位 毫秒）
RuntimeHelper::instance()->stop();

//重新开始计时
RuntimeHelper::instance()->reset();
```

SystemHelper
------------

[](#systemhelper)

```
// 获取内存使用情况
SystemHelper::getMemoryUsage();

// 获取内存使用情况
SystemHelper::logMsg($msg, $file = './log.txt');
```

TreeHelper
----------

[](#treehelper)

```
// 树形递归 , $keyName 作为主键的名称
TreeHelper::getTree($arr, $pid, $keyName = 'pid');
// 返回示例
[{
	"id": "1",
	"pid": "0",
	"name": "test1",
	"children": [{
		"id": "4",
		"pid": "1",
		"name": "test1-1",
		"children": []
	}]
}]
```

DateTimeHelper 时间操作类
--------------------

[](#datetimehelper-时间操作类)

```
//获取上个月的第一天起始时间（一般用于统计比较多）
DateTimeHelper::startMonthDate(-1);
//返回
2019-11-01 00:00:00

//获取下个月的第一天起始时间（一般用于统计比较多）
DateTimeHelper::startMonthDate(1);
//返回
1572566400

//获取上周的第一天（周一）起始时间
DateTimeHelper::startWeekDate(-1);
//返回
2019-11-25 00:00:00

//获取下周的第一天（周一）起始时间
DateTimeHelper::startWeekTime(1);
//返回
1574640000
```

ExcelHelper Excel读取数据工具类，根据excel首行配置，自动映射成数据库字段的数组结构
----------------------------------------------------

[](#excelhelper-excel读取数据工具类根据excel首行配置自动映射成数据库字段的数组结构)

```
/**
    $file: excel 文件路径
    数据库字段 birthday 和excel表头中的数据 "出生日期" 对应，
    数据库字段 name 和excel表头中的数据 "名称" 对应，
    数据库字段 height 和excel表头中的数据 "身高" 对应，
*/

$data = ExcelHelper::instance()->getData($file, ["birthday" => "出生日期", "name" => "名称", "height" => "身高"]);
```

$data 的数据如下：

```
[{
    "B": "男",
    "C": "打篮球",
    "E": 70,
    "G": null,
    "name": "张三",
    "height": 180,
    "birthday": "2000年11月13日"
}, {
    "B": "女",
    "C": null,
    "E": 50,
    "G": null,
    "name": "李四",
    "height": 160,
    "birthday": "2001年12月3日"
}, {
    "B": "女",
    "C": "画画",
    "E": 40,
    "G": null,
    "name": "王五",
    "height": 170,
    "birthday": "1992年1月13日"
}]
```

ExcelExportData Excel导出工具类
--------------------------

[](#excelexportdata-excel导出工具类)

```
1.导出可设置表头数据
2.支持指定默认的表头的宽度
3.可以定制设置某一列表头的宽度

```

使用方法如下：

```
//example
$header = [
    'name' => '名称',
    'birthday' => '生日',
    'hobby' => '爱好',
];
//Set the excel header
$excelExportHeader = new ExcelExportHeader($header);
//可以针对某一列Excel来设置宽度，默认情况 30 的宽度
$excelExportHeader->getHeaderColumnCell('name')->width = 30;
//导出Excel 数据
$excelExportData = new ExcelExportData();
$excelExportData->setExcelExportHeader($excelExportHeader);
//可以选择导出的路径
$path ='/xxx/xxx/temp';
$excelExportData->setFilePath($path);
//data eg: ['excelName' => $excelName, 'file' => $file]
$data = $excelExportData->create($list);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.3% 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 ~63 days

Recently: every ~2 days

Total

10

Last Release

1981d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59315db166fcb1d0c274aa6971a3f997d25f27746e8ef6dc35c6d1f4de5ca262?d=identicon)[Asura](/maintainers/Asura)

---

Top Contributors

[![jasonyqwang](https://avatars.githubusercontent.com/u/5234340?v=4)](https://github.com/jasonyqwang "jasonyqwang (19 commits)")[![ssssssssdd](https://avatars.githubusercontent.com/u/32793124?v=4)](https://github.com/ssssssssdd "ssssssssdd (11 commits)")[![asuratu](https://avatars.githubusercontent.com/u/21030906?v=4)](https://github.com/asuratu "asuratu (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asuratu-utils/health.svg)

```
[![Health](https://phpackages.com/badges/asuratu-utils/health.svg)](https://phpackages.com/packages/asuratu-utils)
```

###  Alternatives

[liuggio/excelbundle

This is a Symfony2 Bundle helps you to read and write Excel files (including pdf, xlsx, odt), thanks to the PHPExcel library

3776.4M10](/packages/liuggio-excelbundle)[wisembly/excelant

72158.3k](/packages/wisembly-excelant)[arogachev/yii2-excel

ActiveRecord import and export based on PHPExcel for Yii 2 framework

6480.3k1](/packages/arogachev-yii2-excel)[archon/dataframe

Archon: PHP Data Analysis Library

9824.2k1](/packages/archon-dataframe)[portphp/excel

Excel reader and writer for Port

26259.9k](/packages/portphp-excel)[netgen/information-collection-bundle

Information collection alike feature for Ibexa Platform

1945.1k9](/packages/netgen-information-collection-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
