Vielen Dank nochmal für alle Antworten!
So konnte ich eine kleine Funktion zur Erkennung des BOM schreiben.
Man speist sie mit den ersten Bytes einer Datei und Sie sollte, falls ein Byte Order Mark erkannt wird, das entsprechende Encoding/Charset für die php-mb-string Konvertierung liefern. Natürlich verbesser- und erweiterbar.
Vielleicht benötigt Sie mal jemand, also poste ich sie gleich mit:
# detect bom and match charset
# ----------------------------
# $first_bytes: 4 leading bytes of file
# $boms: valid byte order marks
function detectBOM($first_bytes=NULL){
if($first_bytes!==NULL){
# valid byte order marks
$boms=array('UTF-8' => '\xEF\xBB\xBF', # utf-8
'UTF-32BE' => '\x00\x00\xFE\xFF', # utf-32 big endian
'UTF-32LE' => '\xFF\xFE\x00\x00', # utf-32 little endian
'UTF-16BE' => '\xFE\xFF', # utf-16 big endian
'UTF-16LE' => '\xFF\xFE'); # utf-16 little endian
# cylcle through boms -> return charset
foreach($boms AS $charset => $bom){
if(preg_match('~^'.$bom.'~',$first_bytes)){
return $charset;
}
}
}
return false;
}
herzliche Grüße,
Jonny 5