PHPackages                             devmastersbv/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. devmastersbv/transcoder

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

devmastersbv/transcoder
=======================

Better encoding conversion for PHP

1.0.6(10y ago)03.2k2MITPHPPHP &gt;=5.4.0

Since Jan 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/devmastersbv/transcoder)[ Packagist](https://packagist.org/packages/devmastersbv/transcoder)[ RSS](/packages/devmastersbv-transcoder/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (1)Versions (8)Used By (2)

Transcoder
==========

[](#transcoder)

Forked from `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
}
```

To override the MbTranscoder or IconvTranscoder class (to include your own hacks) use the following before calling Transcoder::create() for the first time:

```
Transcoder::$iconvClass = "ddeboer\Transcoder\IconvTranscoder";
Transcoder::$mbClass = "ddeboer\Transcoder\MbTranscoder";

```

### 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

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 67.9% 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

Every ~78 days

Recently: every ~0 days

Total

7

Last Release

3713d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c041fd08db5356ee5a458a6afe5f1de68bd2ce660dda21e9c12810fe5581fd0?d=identicon)[DevMastersBV](/maintainers/DevMastersBV)

---

Top Contributors

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

---

Tags

utf-8iconvencodingmultibytembcharsetmb\_convert\_encodingiso

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ddeboer/transcoder

Better encoding conversion for PHP

16719.6k10](/packages/ddeboer-transcoder)[zbateson/mb-wrapper

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

4952.7M7](/packages/zbateson-mb-wrapper)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.3M192](/packages/danielstjules-stringy)[voku/stringy

A string manipulation library with multibyte support

1863.9M26](/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, .....

224.1M18](/packages/onnov-detect-encoding)[paquettg/string-encode

Facilitating the process of altering string encoding in PHP.

699.1M43](/packages/paquettg-string-encode)

PHPackages © 2026

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