byjg / convert
A lightweight utility for string conversion between text from UTF8 to a lot of formats and vice-versa.
Fund package maintenance!
byjg
Installs: 53 466
Dependents: 3
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/byjg/convert
Requires
- php: >=8.1 <8.4
Requires (Dev)
- phpunit/phpunit: ^9.6
- vimeo/psalm: ^5.9
README
A lightweight utility for string conversion between text from UTF8 to various formats and vice-versa. Supports HTML entities, MIME encoded words, accents removal, emoji conversion, and more.
Features
- Convert HTML entities to UTF8 and vice-versa
- Convert ASCII emoticons to emoji characters
- Handle combining characters
- Remove accents from UTF8 text
- Convert text to MIME encoded words (RFC 2047)
- Remove emoji characters
- Convert to ASCII-only text
Documentation
- Converting to UTF8 - Convert from HTML entities, emoticons, and combining characters
- Converting from UTF8 - Convert to HTML entities, remove accents and emoji, ASCII conversion
- Installation - How to install and set up the library
- Examples - Real-world usage examples and common patterns
Quick Start
<?php // Convert HTML entities to UTF8 $str = \ByJG\Convert\ToUTF8::fromHtmlEntities('João'); echo $str; // João // Convert UTF8 to HTML entities $str2 = \ByJG\Convert\FromUTF8::toHtmlEntities('João'); echo $str2; // João // Remove accents $str3 = \ByJG\Convert\FromUTF8::removeAccent('João'); echo $str3; // Joao // Convert to MIME encoded word (for email headers) $str4 = \ByJG\Convert\FromUTF8::toMimeEncodedWord('João'); echo $str4; // =?utf-8?Q?Jo=C3=A3o?= // Convert to ASCII only $str5 = \ByJG\Convert\FromUTF8::onlyAscii('João'); echo $str5; // Joao // Convert ASCII emoticons to emoji $str6 = \ByJG\Convert\ToUTF8::fromEmoji('Hello :) How are you? :D'); echo $str6; // Hello 😊 How are you? 😃 // Remove emoji characters $str7 = \ByJG\Convert\FromUTF8::removeEmoji('Hello 👋 World 🌍'); echo $str7; // Hello World
For more examples and detailed documentation, see the Examples page.
Install
Just type:
composer require "byjg/convert"
Running Tests
vendor/bin/phpunit
Dependencies
flowchart TD
byjg/convert
Loading