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

ActiveLibrary

nnekipelov/forceutf8
====================

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

00PHP

Since Sep 3Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

ipelovforceutf8
===============

[](#ipelovforceutf8)

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.

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

[](#install-via-composer)

`composer require nnekipelov/forceutf8`

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ž

```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1cd4a455a1b58ffbbc65842f6a59cdc0448a9fb166c340db91483370f70339f?d=identicon)[nnekipelov](/maintainers/nnekipelov)

---

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)")[![nnekipelov](https://avatars.githubusercontent.com/u/13661604?v=4)](https://github.com/nnekipelov "nnekipelov (3 commits)")[![hugopakula](https://avatars.githubusercontent.com/u/11698274?v=4)](https://github.com/hugopakula "hugopakula (2 commits)")[![sailenicolas](https://avatars.githubusercontent.com/u/13719436?v=4)](https://github.com/sailenicolas "sailenicolas (2 commits)")[![byjg](https://avatars.githubusercontent.com/u/981924?v=4)](https://github.com/byjg "byjg (2 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)")[![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)")

### Embed Badge

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

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

PHPackages © 2026

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