Skip to content

Instantly share code, notes, and snippets.

@pilif
Created February 21, 2014 16:09
Show Gist options
  • Save pilif/9137070 to your computer and use it in GitHub Desktop.
Save pilif/9137070 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)) {
utf8fix($bucket->data, true);
$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