PHPackages                             wrossmann/costrenc - 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. wrossmann/costrenc

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

wrossmann/costrenc
==================

Stream filter to convert character encoding on-the-fly

v1.0.0(4y ago)04Apache-2.0PHP

Since Jul 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/wrossmann/costrenc)[ Packagist](https://packagist.org/packages/wrossmann/costrenc)[ RSS](/packages/wrossmann-costrenc/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Costrenc - Co\[nvert\] Str\[eam\] Enc\[oding\]
==============================================

[](#costrenc---convert-stream-encoding)

Convert the encoding of data in-flight with PHP's input streams.

Requirements
------------

[](#requirements)

- The `mbstring` extension.

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

[](#installation)

```
composer install wrossmann/costrenc

```

Usage
-----

[](#usage)

```
use wrossmann\Costrenc\Costrenc;

// 1. Define the filter parameters
class UTF16LEtoUTF8 extends Costrenc {
    protected $in_charset = 'UTF-16LE';
    protected $out_charset = 'UTF-8';
}

// 2. Open your stream
$fh = fopen('my_utf16_file.txt');

// 3. Append the filter
stream_filter_register('UTF16LEtoUTF8', 'UTF16LEtoUTF8');
stream_filter_append($fh, 'UTF16LEtoUTF8', STREAM_FILTER_READ);

// 4. Use the stream normally
while( $line = fgets($fh) ) {
  echo $line;
}

```

### Error Handling

[](#error-handling)

Under a very narrow set of circumstances this filter can detect encoding errors. When this happens the default behaviour is to raise an `E_USER_WARNING` and make a best-effort at converting the encoding of the subsequent data, though no guarantees can be made.

You can override this behaviour or otherwise change the method of message dispatch by overriding the `error_dispatch()` function in a manner such as below.

```
class UTF16LEtoUTF8 extends Costrenc {
    protected $in_charset = 'UTF-16LE';
    protected $out_charset = 'UTF-8';

    protected function raise_error($message) {
        thrown new \Exception($message);
    }
}

```

That said, it's worth noting that reliably detecting encoding errors is generally not feasible and this filter will munge malformed data about as happily as any other library.

YMMV

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

1764d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07eeb654c6e5293a620e4eb42138f331bc966fe0c26e54b7581aee28ee5c03c7?d=identicon)[wrossmann](/maintainers/wrossmann)

---

Top Contributors

[![wrossmann](https://avatars.githubusercontent.com/u/4967671?v=4)](https://github.com/wrossmann "wrossmann (1 commits)")

### Embed Badge

![Health badge](/badges/wrossmann-costrenc/health.svg)

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

###  Alternatives

[ctidigital/magento2-configurator

Keep magento persistently configured using files

174317.4k](/packages/ctidigital-magento2-configurator)[comcast/php-legal-licenses

A utility to generate a Licenses file containing the full license text for every dependency in your project for legal purposes.

821.1M9](/packages/comcast-php-legal-licenses)[xfra35/f3-cron

Job scheduling for the PHP Fat-Free Framework

73107.5k](/packages/xfra35-f3-cron)[bagusindrayana/laravel-coordinate

get nearby location from eloquent laravel

3019.7k](/packages/bagusindrayana-laravel-coordinate)

PHPackages © 2026

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