Getting Started
Requirements
Section titled “Requirements”Babel requires PHP 8.2+ with the following extensions:
ext-intl(ICU transliteration)ext-mbstring(multibyte string handling)ext-iconv(encoding conversion)
Installation
Section titled “Installation”Install Babel with composer:
composer require cline/babelBasic Usage
Section titled “Basic Usage”Create a Babel instance from any string:
use Cline\Babel\Babel;
$babel = Babel::from('Héllo Wörld');Fluent Transformations
Section titled “Fluent Transformations”Chain methods for complex transformations:
$slug = Babel::from('Héllo Wörld!') ->toAscii(); // "Hello World!"Null Safety
Section titled “Null Safety”Babel handles null values gracefully:
$babel = Babel::from(null);$babel->isEmpty(); // true$babel->toAscii(); // null$babel->isUtf8(); // true (empty is valid UTF-8)Immutability
Section titled “Immutability”All transformation methods return new instances:
$original = Babel::from('Café');$ascii = $original->toAscii();
$original->value(); // "Café" (unchanged)$ascii; // "Cafe"Quick Examples
Section titled “Quick Examples”Convert to ASCII
Section titled “Convert to ASCII”Babel::from('Żółć')->toAscii(); // "Zolc"Babel::from('北京')->toAscii(); // "bei jing"Babel::from('Привет')->toAscii(); // "Privet"Detect Scripts
Section titled “Detect Scripts”Babel::from('Hello 世界')->containsChinese(); // trueBabel::from('Привет мир')->containsCyrillic(); // trueBabel::from('مرحبا')->isRtl(); // trueClean Strings
Section titled “Clean Strings”Babel::from("Hello\x00World")->removeNonPrintable()->value(); // "HelloWorld"Babel::from('Hello 👋')->removeEmoji()->value(); // "Hello "Grapheme Operations
Section titled “Grapheme Operations”// Split into grapheme clustersBabel::from('Hello')->graphemes(); // ['H', 'e', 'l', 'l', 'o']Babel::from('café')->graphemes(); // ['c', 'a', 'f', 'é']
// Reverse preserving graphemesBabel::from('café')->reverse()->value(); // "éfac"Create Slugs
Section titled “Create Slugs”Babel::from('Héllo Wörld!')->toSlug(); // "hello-world"Next Steps
Section titled “Next Steps”- Conversion - Encoding conversion methods
- Script Detection - Detect scripts and character sets
- Directionality - RTL/LTR detection
- Character Analysis - Analyze string contents
- Normalization - Clean and normalize strings