2017 © Pedro Peláez
 

library mbstring-stream

An mbstring stream conversion filter.

image

enorris/mbstring-stream

An mbstring stream conversion filter.

  • Sunday, February 25, 2018
  • by ericnorris
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,127 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Multibyte String Stream Filter Build Status

A php_user_filter implementation for quickly converting stream character sets without loading the entire string into memory., (*1)

Note: this library does not have the ability to persist state for stateful character sets, and as such, could potentially lose data. See https://github.com/ericnorris/mbstring-stream/issues/1 for an open issue, and this document for more info about stateful character sets., (*2)

Example

// Not required if the file was autoloaded (e.g. using composer)
MultibyteStringStream::registerStreamFilter();

$native_file = fopen('iso-8859-1-file.txt', 'r');

stream_filter_append($native_file, 'convert.mbstring.UTF-8/ISO-8859-1');

$unicode_file = fopen('utf8-file.txt', 'w');

stream_copy_to_stream($native_file, $unicode_file);

mbstring-stream also works as a write filter:, (*3)

$native_file  = fopen('sjis-file.txt', 'r');
$unicode_file = fopen('utf8-file.txt', 'w');

stream_filter_append($unicode_file, 'convert.mbstring.UTF-8/SJIS');

stream_copy_to_stream($native_file, $unicode_file);

Usage

/**
 * resource   $stream        The stream to filter.
 * string     $to_encoding   The encoding to convert to.
 * string     $from_encoding The encoding to convert from. Optional, defaults to mb_internal_encoding()
 * int        $read_write    See http://php.net/manual/en/function.stream-filter-append.php
 * string|int $sub_char      The substitute character to use. Optional, defaults to mb_substitute_character()
 */
stream_filter_append($stream, "convert.mbstring.$to_encoding/$from_encoding", $read_write, $sub_char);

Note: Be careful when using on streams in 'r+' or 'w+' (or similar) modes; by default PHP will assign the filter to both the reading and writing chain. This means it will attempt to convert the data twice - once when writing to the stream, and once when reading from it., (*4)

The Versions

25/02 2018

dev-master

9999999-dev

An mbstring stream conversion filter.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Eric Norris

25/02 2018

v2.0.0

2.0.0.0

An mbstring stream conversion filter.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Eric Norris

21/03 2016

v1.0.0

1.0.0.0

An mbstring stream conversion filter.

  Sources   Download

MIT

The Development Requires

by Eric Norris