承接 cndrsdrmn/php-string-formatter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cndrsdrmn/php-string-formatter

最新稳定版本:v0.2.0

Composer 安装命令:

composer require cndrsdrmn/php-string-formatter

包简介

Provides utilities to format strings by replacing specific wildcards with randomly generated characters

README 文档

README

The php-string-formatter package provides a simple and efficient way to generate formatted strings by replacing placeholders (#, ?, *, %) with random characters, numbers, or a mix of both. It's perfect for creating test data, unique codes, or flexible string patterns.

Features

  • Replace # with random digits (0-9).
  • Replace % with random digits (1-9).
  • Replace ? with random lowercase letters (a-z).
  • Replace * with random digits or letters.
  • Easy integration with PHP projects.

Installation

Install the package via Composer:

composer require cndrsdrmn/php-string-formatter  

Usage

Basic Wildcard Replacement

use Cndrsdrmn\PhpStringFormatter\StringFormatter;

// Replace '#' with random digits (0-9)
echo StringFormatter::numerify('Order-###');  
// Output: Order-123  

// Replace '%' with random digits (1-9)
echo StringFormatter::numerify('Code-%-%-%');  
// Output: Code-3-7-8  

// Replace '?' with random lowercase letters (a-z)
echo StringFormatter::lexify('User-???');  
// Output: User-abc  

// Replace '*' with random digits or letters
echo StringFormatter::bothify('Key-***');  
// Output: Key-a3b  

Advanced Replacement

You can mix and match placeholders in a single string:

echo StringFormatter::bothify('Code-#?%-*?#');  
// Output: Code-3a9-b1c3  

Supported Placeholders

Placeholder Replacement Example Input Example Output
# Random digit (0-9) ### 123
% Random digit (1-9) %%% 456
? Random letter (a-z) ??? abc
* Random digit or letter *** a1b

Methods

numerify(string $string): string

Replaces all # with random digits (0-9) and % with random digits (1-9).

lexify(string $string): string

Replaces all ? with random lowercase letters (a-z).

bothify(string $string): string

Replaces all * with random digits (0-9) or letters (a-z).

Testing

This package can be tested with PHPUnit. To run tests:

composer test  

Contributing

Contributions are welcome! Feel free to fork the repository, submit pull requests, or open issues for suggestions and bug reports.

License

This package is open-source software licensed under the MIT license.

统计信息

  • 总下载量: 404
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-27