PHPackages                             passport-it/forceutf8 - 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. passport-it/forceutf8

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

passport-it/forceutf8
=====================

PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.

v2.0.6(2y ago)037BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jun 8Pushed 2y agoCompare

[ Source](https://github.com/Passport-IT/forceutf8)[ Packagist](https://packagist.org/packages/passport-it/forceutf8)[ Docs](https://github.com/Passport-IT/forceutf8)[ RSS](/packages/passport-it-forceutf8/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

forceutf8
=========

[](#forceutf8)

PHP Class Encoding featuring popular \\ForceUTF8\\Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.

Description
===========

[](#description)

If you apply the PHP function utf8\_encode() to an already-UTF8 string it will return a garbled UTF8 string.

This class addresses this issue and provides a handy static function called \\ForceUTF8\\Encoding::toUTF8().

You don't need to know what the encoding of your strings is. It can be Latin1 (ISO 8859-1), Windows-1252 or UTF8, or the string can have a mix of them. \\ForceUTF8\\Encoding::toUTF8() will convert everything to UTF8.

Sometimes you have to deal with services that are unreliable in terms of encoding, possibly mixing UTF8 and Latin1 in the same string.

Update:

I've included another function, \\ForceUTF8\\Encoding::fixUTF8(), which will fix the double (or multiple) encoded UTF8 string that looks garbled.

Usage:
======

[](#usage)

```
use \ForceUTF8\Encoding;

$utf8_string = Encoding::toUTF8($utf8_or_latin1_or_mixed_string);

$latin1_string = Encoding::toLatin1($utf8_or_latin1_or_mixed_string);

```

also:

```
$utf8_string = Encoding::fixUTF8($garbled_utf8_string);

```

Examples:

```
use \ForceUTF8\Encoding;

echo Encoding::fixUTF8("FÃÂ©dération Camerounaise de Football\n");
echo Encoding::fixUTF8("FÃ©dÃ©ration Camerounaise de Football\n");
echo Encoding::fixUTF8("FÃÂ©dÃÂ©ration Camerounaise de Football\n");
echo Encoding::fixUTF8("FÃÂÂÂÂ©dÃÂÂÂÂ©ration Camerounaise de Football\n");

```

will output:

```
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football

```

Options:
========

[](#options)

By default, `Encoding::fixUTF8` will use the `Encoding::WITHOUT_ICONV` flag, signalling that iconv should not be used to fix garbled UTF8 strings.

This class also provides options for iconv processing, such as `Encoding::ICONV_TRANSLIT` and `Encoding::ICONV_IGNORE` to enable these flags when the iconv class is utilized. The functionality of such flags are documented in the [PHP iconv documentation](http://php.net/manual/en/function.iconv.php).

Examples:

```
use \ForceUTF8\Encoding;

$str = "FÃÂ©dération Camerounaise—de—Football\n"; // Uses U+2014 which is invalid ISO8859-1 but exists in Win1252
echo Encoding::fixUTF8($str); // Will break U+2014
echo Encoding::fixUTF8($str, Encoding::ICONV_IGNORE); // Will preserve U+2014
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT); // Will preserve U+2014

```

will output:

```
Fédération Camerounaise?de?Football
Fédération Camerounaise—de—Football
Fédération Camerounaise—de—Football

```

while:

```
use \ForceUTF8\Encoding;

$str = "čęėįšųūž"; // Uses several characters not present in ISO8859-1 / Win1252
echo Encoding::fixUTF8($str); // Will break invalid characters
echo Encoding::fixUTF8($str, Encoding::ICONV_IGNORE); // Will remove invalid characters, keep those present in Win1252
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT); // Will trasliterate invalid characters, keep those present in Win1252

```

will output:

```
????????
šž
ceeišuuž

```

Install via composer:
=====================

[](#install-via-composer)

Edit your composer.json file to include the following:

```
{
    "require": {
        "neitanod/forceutf8": "~2.0"
    }
}
```

Tips:
=====

[](#tips)

You can tip me with Bitcoin if you want. :)

[![1Awfu4TZpy99H7Pyzt1mooxU1aP2mJVdHP](resources/wallet.jpg)](resources/wallet.jpg)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.8% 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 ~14 days

Total

2

Last Release

1057d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/619b0b810d6eba02e3e5a8fe68c5adb4dca5c06fe5f969b22c4e953a7a225c1b?d=identicon)[Passport-IT](/maintainers/Passport-IT)

---

Top Contributors

[![neitanod](https://avatars.githubusercontent.com/u/2948958?v=4)](https://github.com/neitanod "neitanod (53 commits)")[![mcuadros](https://avatars.githubusercontent.com/u/1573114?v=4)](https://github.com/mcuadros "mcuadros (6 commits)")[![hugopakula](https://avatars.githubusercontent.com/u/11698274?v=4)](https://github.com/hugopakula "hugopakula (2 commits)")[![Passport-IT](https://avatars.githubusercontent.com/u/135957818?v=4)](https://github.com/Passport-IT "Passport-IT (2 commits)")[![byjg](https://avatars.githubusercontent.com/u/981924?v=4)](https://github.com/byjg "byjg (2 commits)")[![maxiwheat](https://avatars.githubusercontent.com/u/1927334?v=4)](https://github.com/maxiwheat "maxiwheat (1 commits)")[![mmarynich](https://avatars.githubusercontent.com/u/11662487?v=4)](https://github.com/mmarynich "mmarynich (1 commits)")[![neoteknic](https://avatars.githubusercontent.com/u/1809652?v=4)](https://github.com/neoteknic "neoteknic (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![podolinek](https://avatars.githubusercontent.com/u/1062993?v=4)](https://github.com/podolinek "podolinek (1 commits)")[![postalservice14](https://avatars.githubusercontent.com/u/46067?v=4)](https://github.com/postalservice14 "postalservice14 (1 commits)")[![redolent](https://avatars.githubusercontent.com/u/650332?v=4)](https://github.com/redolent "redolent (1 commits)")[![superhero](https://avatars.githubusercontent.com/u/839818?v=4)](https://github.com/superhero "superhero (1 commits)")[![CodeLingoBot](https://avatars.githubusercontent.com/u/45469328?v=4)](https://github.com/CodeLingoBot "CodeLingoBot (1 commits)")[![j03k64](https://avatars.githubusercontent.com/u/801500?v=4)](https://github.com/j03k64 "j03k64 (1 commits)")[![j0k3r](https://avatars.githubusercontent.com/u/62333?v=4)](https://github.com/j0k3r "j0k3r (1 commits)")[![LukeUsher](https://avatars.githubusercontent.com/u/740003?v=4)](https://github.com/LukeUsher "LukeUsher (1 commits)")

### Embed Badge

![Health badge](/badges/passport-it-forceutf8/health.svg)

```
[![Health](https://phpackages.com/badges/passport-it-forceutf8/health.svg)](https://phpackages.com/packages/passport-it-forceutf8)
```

###  Alternatives

[tiime/en-16931

EN-16931 compliant invoices as PHP objects

13239.4k3](/packages/tiime-en-16931)

PHPackages © 2026

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