Download the PHP package kit-jotform/php-ftfy without Composer
On this page you can find all versions of the php package kit-jotform/php-ftfy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kit-jotform/php-ftfy
More information about kit-jotform/php-ftfy
Files in kit-jotform/php-ftfy
Package php-ftfy
Short Description Fixes text for you — PHP port of the Python ftfy library
License MIT
Homepage https://github.com/kit-jotform/php-ftfy
Informations about the package php-ftfy
php-ftfy: fixes text for you
A PHP 8.1+ text-fixing library based on the Python ftfy library (version 6.3.1) by Robyn Speer.
What it does
ftfy fixes mojibake — text that was encoded in UTF-8 but decoded as something else (Windows-1252, Latin-1, etc.), producing garbled characters.
Installing
Requirements: PHP >= 8.1, ext-mbstring, ext-intl
Usage
Ftfy::fixText(string $text, ?TextFixerConfig $config = null): string
Fix all encoding issues in a string.
Ftfy::fixEncoding(string $text): string
Fix only encoding/mojibake issues, without applying other text fixes.
Ftfy::needsFix(string $text, ?TextFixerConfig $config = null): bool
Fast dry-run that checks whether text needs fixing without performing corrections. Use as a gate before fixText() on hot paths — 10-26x faster depending on input.
Respects TextFixerConfig — disabled fixers are skipped:
Ftfy::fixAndExplain(string $text, ?TextFixerConfig $config = null): array
Returns ['text' => string, 'explanation' => array] with the fixed text and a list of changes made.
Configuration
Use $config->with(uncurlQuotes: false) to produce a modified copy.
Note on large inputs: Internally, regex matching uses chunked processing for inputs larger than 8 KB to avoid hitting PCRE backtracking/recursion limits. No configuration is needed — this is handled automatically.
Command-line usage
A CLI script is included at bin/ftfy.
Fix a string directly:
Pipe from stdin:
Fix a file:
Show what was fixed (explanation goes to stderr):
Check if text needs fixing (exit code 1 = needs fix):
Override config options with -c key=value (repeatable):
Fix mojibake inside a JSON file with -j (minimal-diff: only changes string values that contain mojibake; preserves whitespace, key order, and untouched escapes):
When mojibake lives inside JSON string values, the raw file contains only ASCII escape sequences like —, so plain php bin/ftfy --needs-fix broken.json reports false — the mojibake bytes only appear after JSON decoding. -j walks the JSON byte-by-byte (no regex, no PCRE recursion limits), decodes each string literal individually, and rewrites only those that needsFix flags. Other strings and all structural bytes pass through verbatim.
-j composes with -n and -e:
Install globally (optional):
Options:
| Option | Short | Description |
|---|---|---|
--explain |
-e |
Print what was fixed (to stderr) |
--needs-fix |
-n |
Print true/false; exit 0 if no fix needed, 1 if fix needed |
--json |
-j |
Fix mojibake inside JSON string values (minimal-diff output; composes with -n and -e) |
--file |
-f |
Read input from a file |
--config key=val |
-c |
Set a TextFixerConfig option (repeatable) |
--help |
-h |
Show help |
Boolean config keys accept true/false/1/0: uncurlQuotes, fixEncoding, fixLineBreaks, fixSurrogates, removeControlChars, removeTerminalEscapes, restoreByteA0, replaceLossySequences, decodeInconsistentUtf8, fixC1Controls, fixLatinLigatures, fixCharacterWidth. String keys: unescapeHtml (auto/true/false), normalization (NFC/NFKC/null), maxDecodeLength (integer).
Running tests
Credits
- Original Python library: ftfy by Robyn Speer, licensed under Apache 2.0
- PHP port licensed under MIT
All versions of php-ftfy with dependencies
ext-mbstring Version *
ext-intl Version *