Olá professor, tentei criar o filtro com o utf8_decode, segue o código:
DecodeFiltro.php:
<?php
class DecodeFiltro extends php_user_filter{
public $stream;
public function onCreate()
{
$this->stream = fopen('php://temp', 'w+');
return $this->stream !== false;
}
public function filter($in, $out, &$consumed, $closing)
{
$saida = '';
while($bucket = stream_bucket_make_writeable($in)){
$lines = explode("\n", $bucket->data);
foreach($lines as $line){
$saida .= utf8_decode("$line\n");
}
}
$bucketSaida = stream_bucket_new($this->stream, $saida);
stream_bucket_append($out, $bucketSaida);
return PSFS_PASS_ON;
}
}
implementacaoFiltroDecode.php:
<?php
require 'DecodeFiltro.php';
$file = fopen('cursos.csv', 'r');
stream_filter_register('file.decode', DecodeFiltro::class);
stream_filter_append($file, 'file.decode');
echo fread($file, filesize('cursos.csv'));