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.
- Host: GitHub
- URL: https://github.com/gh640/sjis-stream-filter
- Owner: gh640
- License: mit
- Created: 2017-08-13T04:16:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-03T13:41:28.000Z (over 8 years ago)
- Last Synced: 2025-01-14T14:17:20.425Z (over 1 year ago)
- Topics: php, php-stream, sjis, utf-8
- Language: PHP
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.