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

5.0.0 2024-10-27 16:13 UTC

This package is auto-updated.

Last update: 2025-11-19 05:15:59 UTC


README

Build Status Opensource ByJG GitHub source GitHub license GitHub release

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

Quick Start

<?php
// Convert HTML entities to UTF8
$str = \ByJG\Convert\ToUTF8::fromHtmlEntities('Jo&atilde;o');
echo $str; // João

// Convert UTF8 to HTML entities
$str2 = \ByJG\Convert\FromUTF8::toHtmlEntities('João');
echo $str2; // Jo&atilde;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

Open source ByJG