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(5y ago)04Apache-2.0PHP

Since Jul 10Pushed 5y ago1 watchersCompare

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

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

23

—

LowBetter than 25% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

1863d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4967671?v=4)[Wade Rossmann](/maintainers/wrossmann)[@wrossmann](https://github.com/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

[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

9.0k747.6M39](/packages/phpdocumentor-reflection-common)[emulsify-ds/emulsify-drupal

The official Drupal theme for Emulsify, with Storybook and a Vite-based build workflow for generated child themes

96561.6k2](/packages/emulsify-ds-emulsify-drupal)[outerweb/filament-settings

Filament integration for the outerweb/settings package

36111.3k4](/packages/outerweb-filament-settings)[imanghafoori/php-imports-analyzer

A command line tool to scan for extra or wrong use statements in composer based apps.

21240.3k25](/packages/imanghafoori-php-imports-analyzer)[selective/luhn

Luhn library, modulo 10

10136.2k1](/packages/selective-luhn)

PHPackages © 2026

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