Skip to content

Instantly share code, notes, and snippets.

@pilif
Created February 21, 2014 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilif/9137146 to your computer and use it in GitHub Desktop.
Save pilif/9137146 to your computer and use it in GitHub Desktop.
<?php
stream_filter_register("utf8encode", "utf8encode_filter");
class utf8encode_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
while($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = utf8_encode($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
/*
usage:
$fh = fopen('somefile', 'r');
stream_filter_prepend($fh, 'utf8encode');
while($row = fgetcsv($fh){
...
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment