An open API service indexing awesome lists of open source software.

https://github.com/gh640/sjis-stream-filter

Provides some PHP stream filters for Shift-JIS encoding.
https://github.com/gh640/sjis-stream-filter

php php-stream sjis utf-8

Last synced: about 1 year ago
JSON representation

Provides some PHP stream filters for Shift-JIS encoding.

Awesome Lists containing this project

README

          

# `gh640/sjis-stream-filter`

Provides 2 simple PHP stream filters for Shift-JIS encoding.

There're 2 filters available in this package.

- `gh640\SjisStreamFilter\Filter\SjisToUtf8Filter`
- `gh640\SjisStreamFilter\Filter\Utf8ToSjisFilter`

## Installation

You can install this package with `composer` command.

```bash
$ composer require gh640/sjis-stream-filter:1.0.0-alpha2
```

## Usage

The following stream filter classes can be used directly with `stream_filter_register()`.

- `gh640\SjisStreamFilter\Filter\SjisToUtf8Filter`
- `gh640\SjisStreamFilter\Filter\Utf8ToSjisFilter`

```php

```

Also, there's a manager class `SjisFilterManager` which allow to use the filters easily.

```php
register(SjisFilterManager::FILTER_SJIS_TO_UTF8);

// Read a file encoded with sjis.
$fp = fopen('a-file-encoded-with-sjis.txt', 'r');
stream_filter_append($fp, $filtername);
while (!feof($fp)) {
$line = fgets($fp);
print $line;
}
fclose($fp);

// Register the utf8-to-sjis filter.
$filtername = $filter_manager->register(SjisFilterManager::FILTER_UTF8_TO_SJIS);

// Write a file with sjis encoding using php://filter.
$content = file_get_contents('utf8.txt');
file_put_contents("php://filter/${filtername}/resource=sjis.txt", $content);

?>
```

You can change the filter name by passing the second argument to `SjisFilterManager::register()`.

```php

```

## License

Licensed under the MIT license.