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

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

fossar/transcoder
=================

Better encoding conversion for PHP

v3.0.0(1y ago)311.5k↑23.1%[2 issues](https://github.com/fossar/transcoder/issues)1MITPHPPHP &gt;=7.4.0

Since Jan 23Pushed 1y agoCompare

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

READMEChangelogDependencies (3)Versions (5)Used By (1)

Transcoder
==========

[](#transcoder)

[![Packagist Version](https://camo.githubusercontent.com/67f992cb6c6b09930f6bd0a0cb9813c0a3e87bd0d5341c8f638a54f7c849dbe2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f737361722f7472616e73636f646572)](https://packagist.org/packages/fossar/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 encodings it does not support
- conversion of warnings to proper exceptions.

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

[](#installation)

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

```
$ composer require fossar/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 a string to ISO-8859-1 encoding:

```
use Ddeboer\Transcoder\Transcoder;

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

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)

The second argument accepts source encoding and can actually be omitted or passed `null`.

```
$transcoder->transcode('España');
```

In that case, however, the behaviour is backend-specific:

- `IconvTranscoder` will use the encoding of the current [locale](https://www.php.net/manual/en/function.setlocale.php) of the process.
- `MbTranscoder` will try to detect encoding from a list based on the value of [`mbstring.language`](https://www.php.net/manual/en/mbstring.configuration.php#ini.mbstring.language) setting. By default, this tries ASCII, followed by UTF-8. The number of [supported languages](https://github.com/php/php-src/blob/d61d21ad57d04b91a1155153811d16ea982fa106/ext/mbstring/mbstring.c#L88-L147) is limited though and the encoding tables often overlap so the detection might be unreliable.

As you can see, this is mostly useless for western languages. You will get much more reliable results when you specify the source encoding explicitly.

### 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', 'iso-8859-1', '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, 'utf-8', 'not-a-real-encoding');
} catch (UnsupportedEncodingException $e) {
    // ‘not-a-real-encoding’ is an unsupported encoding
}

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

try {
    $transcoder->transcode($input);
} catch (UndetectableEncodingException $e) {
    // Failed to automatically detect $input’s encoding (mb) or not a valid string in current locale locale (iconv)
}
```

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

37

—

LowBetter than 81% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 70.3% 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 ~1234 days

Total

4

Last Release

475d ago

Major Versions

v1.0.1 → v2.0.02023-03-07

v2.0.0 → v3.0.02025-03-15

PHP version history (4 changes)1.0.0PHP &gt;=5.4.0

v1.0.1PHP &gt;=5.6.0

v2.0.0PHP &gt;=7.2.5

v3.0.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/575d99972b19f0723a90a2565ba9e9ef1357a7f1b68ea6038c3bf9948ed87b24?d=identicon)[jtojnar](/maintainers/jtojnar)

---

Top Contributors

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

---

Tags

utf-8iconvencodingmultibytembcharsetmb\_convert\_encodingiso

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/fossar-transcoder/health.svg)](https://phpackages.com/packages/fossar-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)
