webpatser/portable-ascii 问题修复 & 功能扩展

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

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

webpatser/portable-ascii

Composer 安装命令:

composer require webpatser/portable-ascii

包简介

Portable ASCII library - modernized for PHP 8.1+ with performance optimizations.

README 文档

README

Modernized drop-in replacement for voku/portable-ascii — requires PHP 8.1+.

Why?

The original voku/portable-ascii package (471M+ installs) still requires PHP 7.0 and has unresolved PHP 8.4 deprecation warnings. This fork modernizes the codebase, fixes transliteration bugs, and is 36-50% faster while keeping full API compatibility.

Zero breaking changes. Same namespace, same methods, same behavior.

What changed

  • PHP 8.1 minimum (was 7.0)
  • Typed properties and return types throughout
  • Fixed implicit nullable parameter deprecation (to_transliterate())
  • Replaced O(n*m) character replacement loop with strtr() — single C-level pass
  • Adaptive sparse/dense detection for optimal replacement strategy
  • mb_str_split() replacing preg_match_all for character splitting (when ext-mbstring available)
  • Cascading transliteration: ext-intl -> ext-iconv -> manual byte decoding
  • Inlined is_ascii() regex for faster hot-path checks
  • Fixed Bulgarian, Ukrainian, Austrian (Eszett), and Hindi transliteration mappings
  • Test suite ported to Pest 4 (247 tests, 1602 assertions)

Performance

Benchmarked on PHP 8.5 with real-world inputs (German/French/Russian blog titles, product names, URL slugs, long text). Each profile was run in an isolated process with 20s CPU cooldown between runs, 5000 iterations, median of 5 runs.

Profile to_ascii to_slugify to_transliterate Total vs Original
original (voku 2.0.3) 742 ms 936 ms 1554 ms 3953 ms
fork (no extensions) 268 ms 382 ms 1540 ms 2455 ms -38%
fork + mbstring 265 ms 378 ms 1174 ms 2073 ms -48%
fork + all extensions 270 ms 371 ms 1171 ms 2072 ms -48%

The to_ascii() and to_slugify() improvements are pure PHP — no extensions needed. ext-mbstring accelerates to_transliterate() by 24% via mb_str_split() replacing preg_match_all for character splitting.

Run the benchmark yourself:

php benchmark/run.php 5000           # fork vs original (side by side)
php benchmark/run-profiles.php 5000  # extension profile comparison

Installation

composer require webpatser/portable-ascii

This automatically replaces voku/portable-ascii via Composer's replace directive. No code changes needed — \voku\helper\ASCII continues to work.

For best transliteration performance, install ext-mbstring:

sudo apt install php-mbstring

Usage

use voku\helper\ASCII;

// Transliterate to ASCII
ASCII::to_ascii('Düsseldorf', 'de');  // 'Duesseldorf'

// Check if string is ASCII
ASCII::is_ascii('hello');  // true

// Transliterate with fallback character
ASCII::to_transliterate('こんにちは', '?');  // 'konnichiha'

// Generate URL slug
ASCII::to_slugify('Hello Wörld!');  // 'hello-woerld'

Compatibility

Works with Laravel 11, 12, and 13. All extensions are optional — the library auto-detects what's available and uses the fastest path.

Extension Impact Used by
ext-mbstring -24% on to_transliterate() mb_str_split() for character splitting
ext-intl Fastest transliteration via ICU to_transliterate() in strict mode only

Credits

This package is a modernized fork of voku/portable-ascii by Lars Moelleken. The original work, including all 193 Unicode-to-ASCII data tables and the transliteration engine, is his. Licensed under MIT.

License

MIT

webpatser/portable-ascii 适用场景与选型建议

webpatser/portable-ascii 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 webpatser/portable-ascii 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-09