spekulatius/php-char-combinator

PHP 的一个可扩展、动态字符列表生成器。

0.0.1 2023-08-28 17:24 UTC

This package is auto-updated.

Last update: 2024-08-28 20:20:46 UTC


README

PHP Char Combinator 是一个实用工具类,它提供方法来根据指定标准生成字符组合数组。

警告

  • 本包不打算在任何 Web 项目中部署。它是一个用于测试的工具 - 不是用于生产。不对任何损害承担责任!
  • 这将生成大量组合,请确保您准备好处理这些数据量。您可能需要调整您的 php.ini

功能

  • 在指定长度范围内生成字符组合数组。
  • 生成 ASCII 字符数组或非字母数字 ASCII 字符数组。
  • 递归组合生成算法,用于生成所有可能的组合。

使用方法

安装

composer require spekulatius/php-char-combinator

基本用法

以下是如何使用 Combinator 类生成字符组合的基本示例

use Spekulatius\PHPCharCombinator\Combinator;

$combinator = new Combinator();

// Generate combinations of lengths 1 to 3 using ASCII characters
$asciiChars = $combinator->prepareAsciiChars();
$combinations = $combinator->generateCombinations($asciiChars, 1, 3);

foreach ($combinations as $combination) {
    echo $combination . "\n";
}

其他方法

Combinator 类提供两种其他方法

prepareAsciiChars()

此方法生成所有 ASCII 字符的数组。

$asciiChars = $combinator->prepareAsciiChars();

prepareNonAlphanumericAsciiChars()

此方法生成非字母数字 ASCII 字符的数组。

$nonAlphanumericChars = $combinator->prepareNonAlphanumericAsciiChars();

贡献

请随意通过在 GitHub 上打开问题或拉取请求来贡献。

许可

本项目是开源的,可在 MIT 许可证 下使用。