PHPackages                             ddeboer/transcoder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ddeboer/transcoder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ddeboer/transcoder
==================

Better encoding conversion for PHP

1.0.0(11y ago)16705.6k↓11.5%15[2 PRs](https://github.com/ddeboer/transcoder/pulls)10MITPHPPHP &gt;=5.4.0

Since Jan 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ddeboer/transcoder)[ Packagist](https://packagist.org/packages/ddeboer/transcoder)[ RSS](/packages/ddeboer-transcoder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (10)

Transcoder
==========

[](#transcoder)

[![Build Status](https://camo.githubusercontent.com/6124d675d09527050357e1c3ce926adb1a3f00b895909e63b8516c3b51df7192/68747470733a2f2f7472617669732d63692e6f72672f646465626f65722f7472616e73636f6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ddeboer/transcoder)[![Release](https://camo.githubusercontent.com/47d9310d67bcc03a5dede6a5cf7034d29078034b436dc836f134e0096442a23c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f646465626f65722f7472616e73636f6465722e7376673f7374796c653d666c6174)](https://packagist.org/packages/ddeboer/transcoder)

Introduction
------------

[](#introduction)

This is a wrapper around PHP’s `mb_convert_encoding` and `iconv` functions. This library adds:

- fallback from `mb` to `iconv` for unknown encodings
- conversion of warnings to proper exceptions.

Installation
------------

[](#installation)

The recommended way to install the Transcoder library is through [Composer](http://getcomposer.org):

```
$ composer require ddeboer/transcoder
```

This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Usage
-----

[](#usage)

### Basics

[](#basics)

Create the right transcoder for your platform and translate some strings:

```
use Ddeboer\Transcoder\Transcoder;

$transcoder = Transcoder::create();
$result = $transcoder->transcode('España');
```

You can also manually instantiate a transcoder of your liking:

```
use Ddeboer\Transcoder\MbTranscoder;

$transcoder = new MbTranscoder();
```

Or:

```
use Ddeboer\Transcoder\IconvTranscoder;

$transcoder = new IconvTranscoder();
```

### Source encoding

[](#source-encoding)

By default, the source encoding is detected automatically. However, you get much more reliable results when you specify it explicitly:

```
$transcoder->transcode('España', 'iso-8859-1');
```

### Target encoding

[](#target-encoding)

Specify a default target encoding as the first argument to `create()`:

```
use Ddeboer\Transcoder\Transcoder;

$isoTranscoder = Transcoder::create('iso-8859-1');
```

Alternatively, specify a target encoding as the third argument in a `transcode()` call:

```
use Ddeboer\Transcoder\Transcoder;

$transcoder->transcode('España', null, 'UTF-8');
```

### Error handling

[](#error-handling)

PHP’s `mv_convert_encoding` and `iconv` are inconvenient to use because they generate notices and warnings instead of proper exceptions. This library fixes that:

```
use Ddeboer\Transcoder\Exception\UndetectableEncodingException;
use Ddeboer\Transcoder\Exception\UnsupportedEncodingException;
use Ddeboer\Transcoder\Exception\IllegalCharacterException;

$input = 'España';

try {
    $transcoder->transcode($input);
} catch (UndetectableEncodingException $e) {
    // Failed to automatically detect $input’s encoding
}

try {
    $transcoder->transcode($input, null, 'not-a-real-encoding');
} catch (UnsupportedEncodingException $e) {
    // ‘not-a-real-encoding’ is an unsupported encoding
}

try {
    $transcoder->transcode('Illegal quotes: ‘ ’', null, 'iso-8859-1');
} catch (IllegalCharacterException $e) {
    // Curly quotes ‘ ’ are illegal in ISO-8859-1
}
```

### Transcoder fallback

[](#transcoder-fallback)

In general, `mb_convert_encoding` is faster than `iconv`. However, as `iconv`supports more encodings than `mb_convert_encoding`, it makes sense to combine the two.

So, the Transcoder returned from `create()`:

- uses `mb_convert_encoding` if the [mbstring](http://php.net/manual/en/book.mbstring.php) PHP extension is installed;
- if not, it uses `iconv` instead if the [iconv](http://php.net/manual/en/book.iconv.php) extension is installed;
- if both the mbstring and iconv extension are available, the Transcoder will first try `mb_convert_encoding` and fall back to `iconv`.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54c045456672a15a85dd65e79418d0f3375322df38ac4dedb5d66487d86ab592?d=identicon)[ddeboer](/maintainers/ddeboer)

---

Top Contributors

[![ddeboer](https://avatars.githubusercontent.com/u/89267?v=4)](https://github.com/ddeboer "ddeboer (19 commits)")

---

Tags

utf-8iconvencodingmultibytembcharsetiso

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ddeboer-transcoder/health.svg)

```
[![Health](https://phpackages.com/badges/ddeboer-transcoder/health.svg)](https://phpackages.com/packages/ddeboer-transcoder)
```

###  Alternatives

[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[zbateson/mb-wrapper

Wrapper for mbstring with fallback to iconv for encoding conversion and string manipulation

4948.6M5](/packages/zbateson-mb-wrapper)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)[onnov/detect-encoding

Text encoding definition class instead of mb\_detect\_encoding. Defines: utf-8, windows-1251, koi8-r, iso-8859-5, ibm866, .....

223.8M8](/packages/onnov-detect-encoding)[paquettg/string-encode

Facilitating the process of altering string encoding in PHP.

698.7M43](/packages/paquettg-string-encode)[statamic/stringy

A string manipulation library with multibyte support, forked from @statamic

234.5M14](/packages/statamic-stringy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
