sjaakp/yii2-helpers

Yii2 PHP 框架的多种辅助工具

安装: 155

依赖: 1

建议: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

1.1.0 2020-03-03 15:44 UTC

This package is auto-updated.

Last update: 2024-08-29 05:36:55 UTC


README

这是一系列针对 Yii 2.0 PHP 框架的辅助工具集合。它们都是抽象类,只在 sjaakp\helpers 命名空间中包含静态函数。

安装

安装 yii2-helpers 的首选方式是通过 Composer。您可以在 composer.json 文件的 require 部分添加以下内容

"sjaakp/yii2-helpers": "*"

或者运行

composer require sjaakp/yii2-helpers "*"

您可以通过 下载 ZIP 格式的源代码 手动安装 yii2-helpers

片段

从字符串中提取一个或多个相关片段。如果片段包含与正则表达式模式匹配的部分,则认为它相关。

  • 静态函数 fragment($subject, $pattern, $radius = 50, $affix = '…', $highlightOptions = [])

    • $subject: string
    • $pattern: PHP 正则表达式模式
    • $radius: int 尝试匹配前后字符的数量。片段大小将是 2 * $radius 加上匹配部分的长度,如果可能的话。
    • $affix: string 如果适用,则在片段前后添加的文本。
    • $highlightOptions: array|false 高亮标签的 HTML 选项。键 'tag' 定义标签类型;如果未设置,则标签类型为 'mark'。如果为 false,则不进行高亮。
    • 返回: string
  • public static function phpPattern($lucenePattern)Zend Lucene 查询字符串 转换为可接受的 PHP 查询字符串。

罗马数字

int 转换为 罗马数字 及其反向转换的函数。

  • static function toInt($roman) 将罗马数字字符串 $roman 转换为 int。无效的 $roman 将转换为 0
  • static function toRoman($int)$int 转换为罗马数字 (1 <= $int <= 3999)。无效的 $int 将转换为空字符串。