Search by

byjg / convert

byjg

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.

Package info

github.com/byjg/php-convert

pkg:composer/byjg/convert

Statistics

Installs: 59 022

Dependents: 3

Suggesters: 0

Stars: 2

Open Issues: 0

6.0.0 2025-11-21 20:54 UTC

This package is auto-updated.

Last update: 2026-10-25 23:49:45 UTC


README

sidebar_key convert
sidebar_category text-content
tags
php text-manipulation

String Conversion Utility

The text conversions UTF-8 code keeps rewriting, in one place: HTML entities, accents, emoji, MIME encoded words and ASCII-only text.

Sponsor Build Status Opensource ByJG Install MCP Server GitHub source GitHub license GitHub release

Why

Each of these is a small function that every project writes again, usually with a bug for a character nobody tested: accents in a slug, an email subject with "ç", user text with :) or emoji that a legacy system cannot store.

Convert has them, both ways:

FromUTF8::removeAccent('João');          // "Joao"
FromUTF8::toMimeEncodedWord('João');     // "=?UTF-8?Q?Jo=C3=A3o?=", for email headers
ToUTF8::fromEmoji('Hello :) <3');        // "Hello 😊 ❤️"
FromUTF8::removeEmoji($userInput);

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.

Installation

Just type:

composer require "byjg/convert"

Running Tests

vendor/bin/phpunit

Open source ByJG