/** * Returns the file encoding * * @return Encoding */ static function detect_encoding($path) { $abstract = array(); // We assume that 200 lines are enough for encoding detection. // here we must get at the raw data so we don't use other functions // it's not possible to read x chars as this would not be safe with utf // (chars may be split in the middle) $handle = fopen($path, 'r'); $i = 0; while (($line = fgets($handle)) !== false && $i < 200) { $i++; $abstract[] = $line; } fclose($handle); $abstract = implode($abstract); return Encoding::detect_encoding($abstract); }