marjovanlier/stringmanipulation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

marjovanlier/stringmanipulation

Composer 安装命令:

composer require marjovanlier/stringmanipulation

包简介

High-performance PHP 8.4+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements. Provides Unicode-aware operations including searchWords(), nameFix(), utf8Ansi(), removeAccents(), and isValidDate() with comprehensive testing infrastructure.

README 文档

README

Table of Contents

Introduction

Welcome to the StringManipulation library, a high-performance PHP 8.4+ toolkit designed for complex and efficient string handling. Following a recent suite of O(n) optimisations, the library is now 2-5x faster, making it one of the most powerful and reliable solutions for developers who require speed and precision in their PHP applications.

This library specialises in Unicode handling, data normalisation, encoding conversion, and validation with comprehensive testing and quality assurance.

Packagist Version Packagist Downloads Packagist License PHP from Packagist Latest Stable PHPStan Enabled Phan Enabled Psalm Enabled codecov

Features

  • removeAccents(): Efficiently strips accents and diacritics to normalise text. Powered by O(n) optimisations using hash table lookups, this high-performance feature makes text comparison and searching faster than ever (981,436+ ops/sec).
  • searchWords(): Transforms strings into a search-optimised format ideal for database queries. This high-performance function intelligently removes irrelevant characters and applies single-pass algorithms to improve search accuracy (387,231+ ops/sec).
  • nameFix(): Standardises names by capitalising letters and correctly handling complex prefixes. Its performance-oriented design with consolidated regex operations ensures consistent data formatting at scale (246,197+ ops/sec).
  • utf8Ansi(): Convert UTF-8 encoded characters to their ANSI equivalents with comprehensive Unicode mappings, facilitating compatibility with legacy systems.
  • isValidDate(): Comprehensive date validation utility that ensures date strings conform to specified formats and validates logical consistency.
  • Comprehensive Unicode/UTF-8 Support: Built from the ground up to handle a wide range of international characters with optimised character mappings, ensuring your application is ready for a global audience.

Performance Benchmarks

The library has undergone extensive performance tuning, resulting in 2-5x speed improvements through O(n) optimisation algorithms. Our benchmarks demonstrate the library's capability to handle high-volume data processing efficiently:

Method Performance Optimisation Technique
removeAccents() 981,436+ ops/sec Hash table lookups with strtr()
searchWords() 387,231+ ops/sec Single-pass combined mapping
nameFix() 246,197+ ops/sec Consolidated regex operations

Benchmarks measured on standard development environments. Actual performance may vary based on hardware, string length, and complexity.

Key Optimisation Features:

  • O(n) complexity algorithms for all core methods
  • Static caching for character mapping tables
  • Single-pass string transformations
  • Minimal memory allocation in critical paths

Installation

Install the package via Composer with the following command:

composer require marjovanlier/stringmanipulation

Usage

For more detailed examples of each feature, please refer to the corresponding sections below.

use MarjovanLier\StringManipulation\StringManipulation;

$result = StringManipulation::searchWords('Hello_World');
echo $result; // Outputs: 'hello world'

License

This library is licensed under the MIT License. For more information, please refer to the License File.

Detailed Examples

Name Standardisation

  • Case Conversion: Easily convert strings between upper case, lower case, and title case, allowing for flexible text formatting and presentation. For example, converting 'john doe' to 'John Doe' for proper name presentation.
use MarjovanLier\StringManipulation\StringManipulation;

$fixedName = StringManipulation::nameFix('mcdonald');
echo $fixedName; // Outputs: 'McDonald'

Search Words

This feature optimises strings for database queries by removing unnecessary characters and optimising for search engine algorithms.

use MarjovanLier\StringManipulation\StringManipulation;

$result = StringManipulation::searchWords('Hello_World');
echo $result; // Outputs: 'hello world'

Name Fix

Standardise last names by capitalising the first letter of each part of the name and handling prefixes correctly.

use MarjovanLier\StringManipulation\StringManipulation;

$fixedName = StringManipulation::nameFix('de souza');
echo $fixedName; // Outputs: 'De Souza'

UTF-8 to ANSI Conversion

Convert UTF-8 encoded characters to their ANSI equivalents, facilitating compatibility with systems that do not support UTF-8.

use MarjovanLier\StringManipulation\StringManipulation;

$ansiString = StringManipulation::utf8Ansi('Über');
echo $ansiString; // Outputs: 'Uber'

Remove Accents

Strip accents and special characters from strings to normalise text, making it easier to search and compare.

use MarjovanLier\StringManipulation\StringManipulation;

$normalisedString = StringManipulation::removeAccents('Crème Brûlée');
echo $normalisedString; // Outputs: 'Creme Brulee'

Date Validation

Ensure date strings conform to specified formats and check for logical consistency, such as correct days in a month.

use MarjovanLier\StringManipulation\StringManipulation;

$isValidDate = StringManipulation::isValidDate('2023-02-29', 'Y-m-d');
echo $isValidDate ? 'Valid' : 'Invalid'; // Outputs: 'Invalid'

Advanced Usage

For more complex string manipulations, consider chaining functions to achieve unique transformations. For instance, you could first normalise a string, apply a search optimisation, and finally standardise the casing for a comprehensive text processing example.

use MarjovanLier\StringManipulation\StringManipulation;

$originalString = 'Crème Brûlée';
$processedString = StringManipulation::nameFix(StringManipulation::utf8Ansi(StringManipulation::removeAccents($originalString)));
echo $processedString; // Outputs: 'Creme Brulee'

This approach allows for flexible and powerful string manipulations by combining the library's functions to suit your specific needs.

Contributing

We welcome contributions to the StringManipulation library! If you're interested in helping, please follow these steps:

  1. Fork the repository and create your feature branch.
  2. Ensure your changes adhere to our coding standards and include tests if applicable.
  3. Submit a pull request with a detailed description of your changes.

Thank you for your interest in improving our library!

Testing & Quality Assurance

We are committed to delivering reliable, high-quality code. Our library is rigorously tested using a comprehensive suite of tools to ensure stability and correctness.

Docker-Based Testing (Recommended)

For a consistent and reliable testing environment, we recommend using Docker. Our Docker setup includes PHP 8.4 with all required extensions:

# Run complete test suite
docker-compose run --rm test-all

# Run individual test suites
docker-compose run --rm test-phpunit      # PHPUnit tests
docker-compose run --rm test-phpstan      # Static analysis
docker-compose run --rm test-code-style   # Code style
docker-compose run --rm test-infection    # Mutation testing

Local Testing

If you have a local PHP 8.4+ environment configured:

# Complete test suite
composer tests

# Individual tests
./vendor/bin/phpunit --filter testClassName
./vendor/bin/phpunit --filter '/::testMethodName$/'

Our Quality Suite Includes:

  • PHPUnit: 166 comprehensive tests with 100% code coverage ensuring functional correctness
  • Mutation Testing: 88% Mutation Score Indicator (MSI) with Infection, guaranteeing our tests are robust and meaningful
  • Static Analysis: Proactive bug detection using:
    • PHPStan (level max, strict rules)
    • Psalm (level 1, 99.95% type coverage)
    • Phan (clean analysis results)
    • PHPMD (mess detection)
  • Code Style: Automated formatting with Laravel Pint (PSR compliance)
  • Performance Benchmarks: Continuous performance monitoring with comprehensive benchmarking suite

System Requirements

  • PHP 8.4 or later (strict typing enabled)
  • mbstring extension for multi-byte string operations
  • intl extension for internationalisation and advanced Unicode support
  • Enabled declare(strict_types=1); for robust type safety
  • Composer for package management

Support

For support, please open an issue on our GitHub repository.

marjovanlier/stringmanipulation 适用场景与选型建议

marjovanlier/stringmanipulation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 859 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「performance」 「validation」 「encoding」 「unicode」 「string manipulation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 marjovanlier/stringmanipulation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 marjovanlier/stringmanipulation 我们能提供哪些服务?
定制开发 / 二次开发

基于 marjovanlier/stringmanipulation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-05