Download the PHP package kode/tools without Composer

On this page you can find all versions of the php package kode/tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tools

kode/tools - PHP8.1+ 通用工具包

简介

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

安装

消息体模块

特性

快速开始

方法说明

方法 说明 示例
Message::result() 返回结果数组,默认code=200, msg="成功" Message::result()
Message::code(int $code) 设置状态码 Message::code(400)
Message::msg(string $msg) 设置消息文本 Message::msg('成功')
Message::data(mixed $data) 设置数据(可选) Message::data(['id' => 1])
Message::page(int $page) 设置页码(动态字段) Message::page(1)
Message::total(int $total) 设置总数(动态字段) Message::total(100)
Message::loadCodes(string $path) 从文件加载状态码 Message::loadCodes('config/codes.php')
Message::codes(array $codes) 合并自定义状态码 Message::codes([800000 => '自定义错误'])

内置状态码

加解密模块

特性

快速开始

特殊字符支持

加解密功能完美支持以下特殊字符:

类型 示例 支持状态
中文 你好世界 ✅ 完全支持
Emoji 😀🎉🚀 ✅ 完全支持
特殊符号 !@#$%^&*()_+-=[]{} ✅ 完全支持
HTML标签 <script>alert("xss")</script> ✅ 完全支持
JSON字符串 {"key":"value"} ✅ 完全支持
多行文本 第一行\n第二行\r\n ✅ 完全支持
空字符 前端\0后端 ✅ 完全支持
SQL注入 '; DROP TABLE users; -- ✅ 完全支持

加密引擎

自动检测并选择最优加密引擎:

引擎 算法 说明
Sodium (推荐) AES-256-GCM 优先使用(PHP8.5+)
Sodium Fallback ChaCha20-Poly1305 Sodium不支持AES-GCM时自动切换
OpenSSL AES-256-GCM Sodium不可用时使用

输出模式

模式 说明 适用场景
MODE_STANDARD 标准Base64 默认,数据存储
MODE_URL_SAFE URL安全Base64 URL参数传输
MODE_COMPACT 十六进制 日志记录、调试

URL传输加解密

URL传输时需要使用MODE_URL_SAFE模式,避免+/=等字符被URL编码:

安全防护

XSS防护

使用Str::xssSafe()防护XSS攻击:

SQL注入防护

使用Str::sqlSafe()防护SQL注入:

HTML转义

使用Str::htmlEscape()转义HTML特殊字符:

方法说明

方法 说明 示例
Crypto::md5(string $str, string $salt) MD5哈希(可选加盐) Crypto::md5('123', 'salt')
Crypto::sha1(string $str, string $salt) SHA1哈希(可选加盐) Crypto::sha1('123', 'salt')
Crypto::sha256(string $str, string $salt) SHA256哈希(可选加盐) Crypto::sha256('123', 'salt')
Crypto::hash(string $data, string $algo) 通用哈希 Crypto::hash('data', 'sha512')
Crypto::passwordHash(string $str) 密码哈希 Crypto::passwordHash('123')
Crypto::passwordVerify(string $str, string $hash) 密码验证 Crypto::passwordVerify('123', $hash)
Crypto::hmac(string $data, string $key, string $algo) HMAC签名 Crypto::hmac('data', 'key')
Crypto::hashEquals(string $known, string $user) 恒时比较 Crypto::hashEquals($a, $b)
Crypto::token(int $length) 生成随机Token Crypto::token(32)
Crypto::uuid() 生成UUID Crypto::uuid()
Crypto::randomString(int $length) 随机字符串 Crypto::randomString(16)
Crypto::orderId(string $prefix) 订单号 Crypto::orderId('ORD')
Crypto::inviteCode(int $length) 邀请码 Crypto::inviteCode(6)
Crypto::verifyCode(int $length) 验证码 Crypto::verifyCode(4)
(new Crypto($key))->encrypt(string $data) AES加密 $c->encrypt('data')
(new Crypto($key))->decrypt(string $data) AES解密 $c->decrypt($encrypted)

HTTP请求模块

特性

快速开始

方法说明

方法 说明 示例
Curl::get(string $url, array $query) GET请求 Curl::get('/users', ['page' => 1])
Curl::post(string $url, mixed $data) POST请求 Curl::post('/users', ['name' => 'x'])
Curl::put(string $url, mixed $data) PUT请求 Curl::put('/users/1', $data)
Curl::delete(string $url) DELETE请求 Curl::delete('/users/1')
Curl::create(string $url) 创建实例 Curl::create('/users')
->send() 发送请求 $curl->send()
->timeout(int $seconds) 超时时间 ->timeout(30)
->headers(array $headers) 设置请求头 ->headers(['Auth' => 'xxx'])
->withJson(mixed $data) JSON数据 ->withJson(['id' => 1])
->withForm(array $data) 表单数据 ->withForm(['name' => 'x'])
->authorization(string $token) Bearer认证 ->authorization('xxx')
->proxy(string $host, int $port) 代理设置 ->proxy('127.0.0.1', 8080)
->retry(int $times, int $delay) 重试机制 ->retry(3, 1000)
->then(callable $onFulfilled) 成功回调 ->then(fn($r) => $r->json())
->catch(callable $onRejected) 错误回调 ->catch(fn($r) => $r->error)

Response方法

方法 说明 示例
->isSuccess() 是否成功(2xx) $res->isSuccess()
->isRedirect() 是否重定向(3xx) $res->isRedirect()
->isClientError() 客户端错误(4xx) $res->isClientError()
->isServerError() 服务端错误(5xx) $res->isServerError()
->isJson() 是否JSON $res->isJson()
->json() 获取JSON数据 $res->json()
->getContent() 获取内容 $res->getContent()
->getStatusCode() 状态码 $res->getStatusCode()

数组处理模块

特性

快速开始

方法说明

方法 说明 示例
Arr::tree(array $list, string $idField, string $parentIdField) 数组转树形 Arr::tree($list, 'id', 'pid')
Arr::list(array $tree, string $childrenField) 树形转数组 Arr::list($tree, 'children')
Arr::level(array $list, string $idField, string $parentIdField) 计算层级 Arr::level($list, 'id', 'pid')
Arr::path(array $list, string $idField, string $parentIdField, string $nameField) 获取路径 Arr::path($list, 'id', 'pid', 'name')
Arr::first(array $array) 获取第一个元素 Arr::first([1,2,3])
Arr::last(array $array) 获取最后一个元素 Arr::last([1,2,3])
Arr::find(array $array, callable $callback) 查找满足条件的元素 Arr::find($arr, fn($v)=>$v>1)
Arr::filter(array $array, callable $callback) 过滤数组 Arr::filter($arr, fn($v)=>$v>0)
Arr::map(array $array, callable $callback) 遍历修改 Arr::map($arr, fn($v)=>$v*2)
Arr::reduce(array $array, callable $callback, mixed $initial) 合并为单一值 Arr::reduce($arr, fn($c,$v)=>$c+$v, 0)
Arr::deepMerge(array $array1, array $array2) 深度合并 Arr::deepMerge($a1, $a2)
Arr::group(array $array, string $key) 分组 Arr::group($arr, 'category')
Arr::sort(array $array, string $key, string $order) 排序 Arr::sort($arr, 'id', 'asc')
Arr::unique(array $array) 去重 Arr::unique($arr)
Arr::chunk(array $array, int $size) 分块 Arr::chunk($arr, 10)
Arr::flatten(array $array) 扁平化 Arr::flatten($tree)
Arr::paginate(array $array, int $page, int $size) 分页 Arr::paginate($arr, 1, 10)
Arr::sum(array $array, string $key) 求和 Arr::sum($arr, 'price')
Arr::avg(array $array, string $key) 平均值 Arr::avg($arr, 'score')
Arr::max(array $array, string $key) 最大值 Arr::max($arr, 'price')
Arr::min(array $array, string $key) 最小值 Arr::min($arr, 'price')
Arr::random(array $array) 随机取一个 Arr::random($arr)
Arr::randomMany(array $array, int $num) 随机取多个 Arr::randomMany($arr, 3)
Arr::column(array $array, string $columnKey) 提取列 Arr::column($arr, 'name')
Arr::pluck(array $array, string $key) 提取值列表 Arr::pluck($arr, 'id')

字符串处理模块

特性

快速开始

方法说明

方法 说明 示例
脱敏方法
Str::maskPhone(string $phone) 手机号脱敏 Str::maskPhone('13800138000')
Str::maskEmail(string $email) 邮箱脱敏 Str::maskEmail('[email protected]')
Str::maskIdCard(string $idCard) 身份证脱敏 Str::maskIdCard('110101199001011234')
Str::maskBankCard(string $bankCard) 银行卡脱敏 Str::maskBankCard('6222021234567890')
Str::mask(string $str, int $start, int $length) 自定义脱敏 Str::mask('abc', 1, 1)
命名转换
Str::camel(string $str) 转驼峰 Str::camel('hello_world')
Str::snake(string $str) 转蛇形 Str::snake('helloWorld')
Str::studly(string $str) 转大驼峰 Str::studly('hello_world')
编码转换
Str::toBase64(string $str) 字符串转Base64 Str::toBase64('hello')
Str::fromBase64(string $base64) Base64转字符串 Str::fromBase64('aGVsbG8=')
Str::toJson(mixed $data) 转JSON Str::toJson(['a' => 1])
Str::fromJson(string $json) JSON转数据 Str::fromJson('{"a":1}')
Str::toXml(array $data) 转XML Str::toXml(['a' => 1])
Str::fromXml(string $xml) XML转数组 Str::fromXml('<root><a>1</a></root>')
Str::toArray(string $str, string $delimiter) 字符串转数组 Str::toArray('a,b,c')
Str::fromArray(array $array, string $delimiter) 数组转字符串 Str::fromArray(['a','b'])
字符串判断
Str::contains(string $str, string $needle) 是否包含 Str::contains('hello', 'll')
Str::startsWith(string $str, string $prefix) 是否开头 Str::startsWith('hello', 'he')
Str::endsWith(string $str, string $suffix) 是否结尾 Str::endsWith('hello', 'lo')
字符串截取
Str::substr(string $str, int $start, ?int $length) 截取字符串 Str::substr('hello', 0, 3)
Str::mbSubstr(string $str, int $start, ?int $length) 中文截取 Str::mbSubstr('你好', 0, 1)
Str::truncate(string $str, int $length, string $suffix) 按长度截断 Str::truncate('abc', 2)
Str::limit(string $str, int $limit, string $end) 按显示宽度截断 Str::limit('你好世界', 5)
Str::length(string $str) 获取长度 Str::length('hello')
Str::mbLength(string $str) 中文长度 Str::mbLength('你好')
字符串修改
Str::replace(string $str, string $search, string $replace) 替换 Str::replace('a', 'b', 'a')
Str::remove(string $str, string $search) 删除 Str::remove('ab', 'b')
Str::reverse(string $str) 反转 Str::reverse('abc')
Str::shuffle(string $str) 随机打乱 Str::shuffle('abc')
Str::repeat(string $str, int $times) 重复 Str::repeat('a', 3)
Str::pad(string $str, int $length, string $pad, int $type) 填充 Str::pad('a', 5, '0', STR_PAD_LEFT)
Str::trim(string $str) 去空格 Str::trim(' abc ')
Str::ucfirst(string $str) 首字母大写 Str::ucfirst('hello')
Str::lcfirst(string $str) 首字母小写 Str::lcfirst('Hello')
Str::title(string $str) 首字母大写词 Str::title('hello world')
验证方法
Str::validatePhone(string $phone, string $region) 验证手机号 Str::validatePhone('13800138000')
Str::validateEmail(string $email) 验证邮箱 Str::validateEmail('[email protected]')
Str::validateIdCard(string $idCard) 验证身份证 Str::validateIdCard('110101199001011234')
Str::validateCarPlate(string $plate) 验证车牌 Str::validateCarPlate('京A12345')
安全方法
Str::sqlSafe(string $str, bool $strict) SQL安全 Str::sqlSafe('abc')
Str::xssSafe(string $str, bool $strict) XSS安全 Str::xssSafe('<script>')
Str::htmlEscape(string $str) HTML转义 Str::htmlEscape('<')
Str::htmlUnescape(string $str) HTML反转义 Str::htmlUnescape('&lt;')
其他方法
Str::uuid() 生成UUID Str::uuid()
Str::random(int $length, string $mode) 随机字符串 Str::random(16)
Str::clean(string $str, array $options) 清理字符串 Str::clean(' abc ')
Str::similarity(string $str1, string $str2) 相似度 Str::similarity('abc', 'abd')
Str::split(string $str, string\|array $delimiters) 分割字符串 Str::split('a,b', ',')
Str::toBool(string $str) 转布尔 Str::toBool('true')
Str::toInt(string $str) 转整数 Str::toInt('123')
Str::toFloat(string $str) 转浮点数 Str::toFloat('1.23')
Str::compress(string $str, int $level) 压缩 Str::compress('很长字符串')
Str::decompress(string $str) 解压 Str::decompress($compressed)

时间处理模块

特性

快速开始

方法说明

方法 说明 示例
Time::now(string $format) 当前时间 Time::now()
Time::today(string $format) 今天日期 Time::today()
Time::yesterday(string $format) 昨天 Time::yesterday()
Time::tomorrow(string $format) 明天 Time::tomorrow()
Time::format(?int $timestamp, string $format) 格式化时间 Time::format(time(), 'Y-m-d')
Time::diffForHumans(int\|string $timestamp) 人性化显示 Time::diffForHumans('2024-01-01')
Time::add(int $timestamp, int $interval) 时间加秒 Time::add(time(), 86400)
Time::sub(int $timestamp, int $interval) 时间减秒 Time::sub(time(), 3600)
Time::diff(int $start, int $end) 差值(秒) Time::diff($t1, $t2)
Time::weekStart(?int $timestamp) 本周开始 Time::weekStart()
Time::weekEnd(?int $timestamp) 本周结束 Time::weekEnd()
Time::monthStart(?int $timestamp) 本月开始 Time::monthStart()
Time::monthEnd(?int $timestamp) 本月结束 Time::monthEnd()
Time::yearStart(?int $timestamp) 今年开始 Time::yearStart()
Time::yearEnd(?int $timestamp) 今年结束 Time::yearEnd()
Time::lastWeekStart(?int $timestamp) 上周开始 Time::lastWeekStart()
Time::lastWeekEnd(?int $timestamp) 上周结束 Time::lastWeekEnd()
Time::lastMonthStart(?int $timestamp) 上月开始 Time::lastMonthStart()
Time::lastMonthEnd(?int $timestamp) 上月结束 Time::lastMonthEnd()
Time::between(int $timestamp, int $start, int $end) 是否在范围内 Time::between(time(), $s, $e)
Time::isToday(int $timestamp) 是否今天 Time::isToday($ts)
Time::isYesterday(int $timestamp) 是否昨天 Time::isYesterday($ts)
Time::isTomorrow(int $timestamp) 是否明天 Time::isTomorrow($ts)
Time::isThisWeek(int $timestamp) 是否本周 Time::isThisWeek($ts)
Time::isThisMonth(int $timestamp) 是否本月 Time::isThisMonth($ts)
Time::isThisYear(int $timestamp) 是否今年 Time::isThisYear($ts)
Time::dayOfWeek(int $timestamp) 星期几(0-6) Time::dayOfWeek(time())
Time::dayOfWeekName(int $timestamp) 星期几名称 Time::dayOfWeekName(time())
Time::dayOfYear(int $timestamp) 第几天 Time::dayOfYear(time())
Time::weekOfYear(int $timestamp) 第几周 Time::weekOfYear(time())
Time::daysInMonth(int $month, int $year) 月天数 Time::daysInMonth(2, 2024)
Time::age(string $birthday) 年龄 Time::age('1990-01-01')
Time::toTimestamp(string $timeStr) 转时间戳 Time::toTimestamp('2024-01-01')
Time::toMillisecond(?int $timestamp) 毫秒时间戳 Time::toMillisecond()
Time::fromMillisecond(int $millisecond) 毫秒转时间戳 Time::fromMillisecond($ms)
Time::millisecond() 当前毫秒 Time::millisecond()
Time::microsecond() 当前微秒 Time::microsecond()
Time::microtime() 当前微秒时间 Time::microtime()
Time::setTimezone(string $timezone) 设置时区 Time::setTimezone('Asia/Shanghai')

数学计算模块

特性

快速开始

方法说明

方法 说明 示例
基础运算
Math::add(float\|int\|string $num1, float\|int\|string $num2, int $scale) 加法 Math::add('1.1', '2.2')
Math::sub(float\|int\|string $num1, float\|int\|string $num2, int $scale) 减法 Math::sub('5.5', '3.3')
Math::mul(float\|int\|string $num1, float\|int\|string $num2, int $scale) 乘法 Math::mul('1.5', '2.5')
Math::div(float\|int\|string $num1, float\|int\|string $num2, int $scale) 除法 Math::div('10', '3')
Math::mod(float\|int\|string $num1, float\|int\|string $num2) 取模 Math::mod('10', '3')
Math::pow(float\|int\|string $num, int $exponent, int $scale) 幂运算 Math::pow('2', 10)
Math::sqrt(float\|int\|string $num, int $scale) 平方根 Math::sqrt('2')
Math::abs(float\|int\|string $num) 绝对值 Math::abs('-5')
Math::round(float\|int\|string $num, int $precision) 四舍五入 Math::round('3.5')
Math::ceil(float\|int\|string $num, int $precision) 向上取整 Math::ceil('3.1')
Math::floor(float\|int\|string $num, int $precision) 向下取整 Math::floor('3.9')
Math::compare(float\|int\|string $num1, float\|int\|string $num2) 比较(-1/0/1) Math::compare('1', '2')
Math::equal(float\|int\|string $num1, float\|int\|string $num2, int $scale) 是否相等 Math::equal('1.0', '1')
Math::format(float\|int\|string $num, int $precision, bool $thousandsSeparator) 格式化数字 Math::format('1000', 2)
金融计算
Math::discount(float\|int\|string $price, float\|int\|string $discount, int $scale) 折扣价 Math::discount('100', '0.8')
Math::tax(float\|int\|string $amount, float\|int\|string $rate, int $scale) 税额 Math::tax('100', '0.13')
Math::taxIncluded(float\|int\|string $amount, float\|int\|string $rate, int $scale) 含税价 Math::taxIncluded('100', '0.13')
Math::taxExcluded(float\|int\|string $amount, float\|int\|string $rate, int $scale) 不含税价 Math::taxExcluded('113', '0.13')
Math::percentage(float\|int\|string $part, float\|int\|string $total, int $scale) 百分比 Math::percentage('25', '100')
Math::simpleInterest(float\|int\|string $principal, float\|int\|string $rate, int $years) 单利 Math::simpleInterest('1000', '0.05', 2)
Math::compoundInterest(float\|int\|string $principal, float\|int\|string $rate, int $years) 复利 Math::compoundInterest('1000', '0.05', 2)
三角函数
Math::sin(float\|int\|string $num, int $scale) 正弦 Math::sin('0')
Math::cos(float\|int\|string $num, int $scale) 余弦 Math::cos('0')
Math::tan(float\|int\|string $num, int $scale) 正切 Math::tan('1')
Math::asin(float\|int\|string $num, int $scale) 反正弦 Math::asin('0.5')
Math::acos(float\|int\|string $num, int $scale) 反余弦 Math::acos('0.5')
Math::atan(float\|int\|string $num, int $scale) 反正切 Math::atan('1')
对数函数
Math::ln(float\|int\|string $num, int $scale) 自然对数 Math::ln('2.718')
Math::log10(float\|int\|string $num, int $scale) 常用对数 Math::log10('100')
Math::log(float\|int\|string $num, float\|int\|string $base, int $scale) 对数 Math::log('8', '2')
Math::rad2deg(float\|int\|string $num, int $scale) 弧度转角度 Math::rad2deg('3.14')
Math::deg2rad(float\|int\|string $num, int $scale) 角度转弧度 Math::deg2rad('180')
数论函数
Math::factorial(int $num) 阶乘 Math::factorial(5)
Math::gcd(int $num1, int $num2) 最大公约数 Math::gcd('12', '18')
Math::lcm(int $num1, int $num2) 最小公倍数 Math::lcm('4', '6')
Math::isPrime(int $num) 是否质数 Math::isPrime(7)
Math::isEven(int $num) 是否偶数 Math::isEven(4)
Math::isOdd(int $num) 是否奇数 Math::isOdd(3)
判断函数
Math::isPositive(float\|int\|string $num) 是否正数 Math::isPositive('1')
Math::isNegative(float\|int\|string $num) 是否负数 Math::isNegative('-1')
Math::isZero(float\|int\|string $num, int $scale) 是否零 Math::isZero('0')
Math::isValid(mixed $num) 是否有效数字 Math::isValid('123')
Math::inRange(float\|int\|string $num, float\|int\|string $min, float\|int\|string $max) 是否在范围内 Math::inRange('5', '1', '10')
Math::clamp(float\|int\|string $num, float\|int\|string $min, float\|int\|string $max) 限制范围 Math::clamp('15', '1', '10')
插值与随机
Math::lerp(float\|int\|string $start, float\|int\|string $end, float\|int\|string $t, int $scale) 线性插值 Math::lerp('0', '100', '0.5')
Math::random(float\|int\|string $min, float\|int\|string $max, int $scale) 随机数 Math::random('1', '100')
统计函数
Math::average(array $numbers, int $scale) 平均值 Math::average([1,2,3])
Math::median(array $numbers, int $scale) 中位数 Math::median([1,2,3,4,5])
Math::mode(array $numbers) 众数 Math::mode([1,2,2,3])
Math::standardDeviation(array $numbers, int $scale) 标准差 Math::standardDeviation([1,2,3])
Math::variance(array $numbers, int $scale) 方差 Math::variance([1,2,3])

地理位置模块

特性

快速开始

方法说明

方法 说明 示例
Geo::distance(float $lat1, float $lon1, float $lat2, float $lon2, string $unit) 两点距离 Geo::distance($lat1, $lon1, $lat2, $lon2)
Geo::isValid(float $lat, float $lon) 坐标验证 Geo::isValid(39.9042, 116.4074)
Geo::toRadians(float $degrees) 度转弧度 Geo::toRadians(180)
Geo::toDegrees(float $radians) 弧度转度 Geo::toDegrees(3.14)
Geo::midpoint(float $lat1, float $lon1, float $lat2, float $lon2) 中点坐标 Geo::midpoint($lat1, $lon1, $lat2, $lon2)
Geo::bearing(float $lat1, float $lon1, float $lat2, float $lon2) 方位角(度) Geo::bearing($lat1, $lon1, $lat2, $lon2)
Geo::toDMS(float $decimal, bool $isLatitude) 十进制转度分秒 Geo::toDMS(39.9042, true)
Geo::toDecimal(int $degrees, int $minutes, float $seconds, string $direction) 度分秒转十进制 Geo::toDecimal(39, 54, 15.12, 'N')

IP地址模块

特性

快速开始

方法说明

方法 说明 示例
Ip::get(bool $checkProxy) 获取客户端IP Ip::get()
Ip::getRealIp() 获取真实IP Ip::getRealIp()
Ip::isValid(string $ip) IP验证 Ip::isValid('192.168.1.1')
Ip::isPrivate(string $ip) 是否私有IP Ip::isPrivate('192.168.1.1')
Ip::isPublic(string $ip) 是否公网IP Ip::isPublic('8.8.8.8')
Ip::getVersion(string $ip) IP版本(4/6) Ip::getVersion('192.168.1.1')
Ip::getType(string $ip) IP类型 Ip::getType('192.168.1.1')
Ip::toLong(string $ip) IP转整数 Ip::toLong('192.168.1.1')
Ip::fromLong(int $long) 整数转IP Ip::fromLong(3232235777)
Ip::getLocation(string $ip, ?string $apiKey) IP归属地 Ip::getLocation('8.8.8.8')
Ip::isFromCountry(string $ip, string $countryCode) 是否某国IP Ip::isFromCountry('8.8.8.8', 'US')

二维码模块

特性

快速开始

方法说明

方法 说明 示例
Qr::text(string $content) 设置内容 Qr::text('hello')
Qr::size(int $size) 二维码尺寸 Qr::size(300)
Qr::margin(int $margin) 边距 Qr::margin(10)
Qr::foregroundColor(string $color) 前景色 Qr::foregroundColor('#000000')
Qr::backgroundColor(string $color) 背景色 Qr::backgroundColor('#ffffff')
Qr::logo(string $path) Logo路径 Qr::logo('logo.png')
Qr::generate() 生成图片 $qr->generate()
Qr::save(string $path) 保存文件 $qr->save('qr.png')
Qr::base64() 返回Base64 $qr->base64()

全局辅助函数

使用composer require后,全局函数自动加载:

许可证

MIT License


All versions of tools with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-openssl Version *
ext-json Version *
ext-mbstring Version *
ext-gd Version *
endroid/qr-code Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kode/tools contains the following files

Loading the files please wait ...