Created
February 21, 2014 16:13
-
-
Save pilif/9137146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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