~/docs
Resonate
Resonate
3.x 3.1.1, current
Portable ASCII
Toggle sidebar
Portable ASCII
webpatser/portable-ascii 3.1.1

Portable ASCII 3.x

Installation

Install webpatser/portable-ascii with Composer, check the requirements and see how the Fledge variant differs.

Portable ASCII is a PHP library of static string functions for ASCII handling: transliteration, slugs, safe filenames and cleanup of invisible or malformed characters. Everything lives in the voku\helper\ASCII class. The package is webpatser/portable-ascii and has no runtime dependencies.

webpatser/portable-ascii is derived from the voku/portable-ascii project. It keeps the namespace, the 15 public methods of the original class and the Unicode-to-ASCII data tables, requires PHP 8.1 and fixes several transliteration tables. Existing code that uses the class runs unchanged, apart from the removed $remove_invalid_utf8 parameter of clean() (see the API Reference page).

This documentation covers 3.1.1.

Install

composer require webpatser/portable-ascii

Note: No tagged release is on Packagist yet; it lists only the dev-main branch, which is the 3.1.1 code. Until a tag is published, require the branch explicitly: composer require webpatser/portable-ascii:dev-main.

The package's composer.json declares replace for the original package ("voku/portable-ascii": "2.0.99"), so Composer installs it in its place for every package that depends on it (Laravel's Str::ascii(), Str::slug() and Str::transliterate() among them). No code changes are needed.

Requirements

  • PHP 8.1 or higher.
  • No extensions are required. The class detects at runtime which extensions are loaded and uses the fastest available path.
  • ext-mbstring is suggested. When it is loaded, to_transliterate() splits characters with mb_str_split() instead of preg_match_all(), and clean() strips invalid UTF-8 with mb_convert_encoding() instead of a regex.
  • ext-intl is suggested. It provides transliterator_transliterate() for the strict mode of ASCII::to_transliterate().

Use it

<?php
 
use voku\helper\ASCII;
 
echo ASCII::to_ascii('Düsseldorf', 'de'); // Duesseldorf
echo ASCII::to_ascii('Düsseldorf', 'en'); // Dusseldorf

Continue with the Quick Start page.

Fledge variant

webpatser/fledge-portable-ascii (release v2.0.0) is a PHP 8.6 build of webpatser/portable-ascii for Fledge.

composer require webpatser/fledge-portable-ascii

What differs from webpatser/portable-ascii:

  • It requires PHP ^8.6 and ext-mbstring. Both are mandatory.
  • It removes the runtime capability detection. It calls mb_str_split() directly instead of falling back to preg_match_all(), and always uses mb_convert_encoding() for UTF-8 cleaning.
  • It has no setCapabilities() method.
  • ext-intl stays optional and is used for strict transliteration.
  • It supports only the latest stable PHP release. A new PHP release means a new package release that requires it.
  • Its composer.json declares replace entries for the original package and for webpatser/portable-ascii, so it takes the place of both.

The other 15 public methods have the same signatures, and the namespace stays voku\helper\ASCII:

<?php
 
use voku\helper\ASCII;
 
ASCII::to_ascii('Düsseldorf', 'de'); // 'Duesseldorf'
ASCII::is_ascii('hello'); // true