1 Star 0 Fork 0

小马哥/php-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
5天前
11天前
2年前
5天前
Loading...
README
MIT

简介

php 一些常用的扩展

自动化测试

项目跟目录下执行

./vendor/bin/phpunit

类说明

Console.php

use magein\utils\Console;
Console::error('失败');
Console::success('成功');
Console::warning('警告');
Console::white('政策');
Console::red('红色');
Console::blue('蓝色');
Console::green('绿色');
Console::yellow('黄色');

DateFormatter.php

use magein\utils\DateFormatter;
DateFormatter::now();
DateFormatter::unixtime('2025-06-18 14:55:31');
DateFormatter::date('2025-06-18 14:55:31');
DateFormatter::time('2025-06-18 14:55:31');
DateFormatter::datetime('1750230185');
DateFormatter::today();
DateFormatter::yesterday();
DateFormatter::dayRange();
DateFormatter::tomorrow();
// 上周
DateFormatter::lastWeek();
// 前几天的数据 不包含今天
DateFormatter::prevDay();
// 近几天的数据 包含今天
DateFormatter::lastDay();

BrowserAgent.php

use magein\utils\BrowserAgent;
BrowserAgent::random();
BrowserAgent::android();
// 返回一个数组包含user-agent参数
BrowserAgent::header();

Validator.php

常用的验证类

use magein\utils\Validator;

Validator::phone();
Validator::email();
Validator::qq();
Validator::idCard();
Validator::url();
Validator::http();
Validator::https();
Validator::ip();
Validator::ipv4();
Validator::ipv6();
Validator::image();
Validator::chinese();

Result.php

用于方法的返回值

Faker.php

用于生成数据

use magein\utils\Faker;
Faker::email();
Faker::phone();
Faker::text();
Faker::phone();
Faker::name();
Faker::title();

Location.php

规范经纬度取值,仅仅是规范不同地图取值经纬度前后的问题,腾讯地址返回维度在前,高德返回经度在前

仅仅适用与中国范围内的经纬度

use magein\utils\Location;

$number = '39.5420,116.2529';
$location = Location::init($number);
// 经度在前的字符串
$location->toString();
$location->toArray();
// 返回带键的数组通过 longitude和latitude
$location->toArray(false);
// 获取经度
$location->getLongitude();
// 获取维度
$location->getLatitude();

Http.php

使用需要安装GuzzleHttp

composer require guzzlehttp/guzzle:^7.6

$http = new \magein\utils\Http;
// 要添加到请求的查询字符串的关联数组或查询字符串
$http->get($url,$params=[]);
// 用来发送一个 application/x-www-form-urlencoded POST请求
$http->formParams($url,$params);
// 设置请求的主体为 multipart/form-data 表单 
$http->multipartFormData($url,$params);
$http->json($url,$params,'post');
$http->body($url,$params,'put');

Tree.php


$tree = new \magein\utils\Tree($data);
$data=$tree->transfer();

// 设置主键ID
$tree->setPrimary('id');
// 设置父级索引 默认parent_id
$tree->setParentId('pid');
// 设置子集索引 默认child
$tree->setChild('children');

// 数据结构转化成一维数组
$tree->floor($url,$params);
// 设置请求的主体为 multipart/form-data 表单
MIT License Copyright (c) 2023 小马哥 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

php开发使用的工具类 不依赖框架 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者 (1)

全部

语言

近期动态

5天前推送了新的 v3.0.1 标签
5天前推送了新的提交到 v3 分支,3dd15c0...1c7d3a1
5天前推送了新的提交到 v4 分支,2ba572c...f998037
5天前推送了新的 v4.0.0 标签
5天前推送了新的提交到 master 分支,00fb92d...f998037
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/magein/php-utils.git
git@gitee.com:magein/php-utils.git
magein
php-utils
php-utils
master

搜索帮助