Maike: explode() erzeugt Leerzeichen wo keine sein sollten!

Beitrag lesen

Hallo liebes Self-Forum,

ich hab ein großes Problem. Ich hab ein Script geschrieben, das nicht so funktioniert wie ich mir das vorstelle:

<?PHP
echo "<html><head></head><body>";

$file = "test.txt";
$datei = file($file);

for($x=0;$x<count($datei);$x++)
{
 $parts = explode("|", $datei[$x]);
 $gid   = trim($parts[0]);
 $bid   = trim($parts[1]);
 $timestamp  = trim($parts[2]);
 $ip   = trim($parts[3]);
 $name   = trim($parts[4]);
 $kommentar  = trim($parts[5]);
 echo "$gid, $bid, $timestamp, $ip, $name, $kommentar <br>\n";
}
echo "</body></html>";
?>

Inhalt der test.txt:
1|3|1046249704|80.145.122.17|test|Hi Andy, BACK IN BLACK, wie wir dich kennen. *g*|
1|3|1055159178|80.145.122.17||so sind sie halt, die WIB|

Ausgabe des Scripts:
<html><head></head><body>ÿþ1, 3, 1 0 4 6 2 4 9 7 0 4, 8 0 . 1 4 5 . 1 2 2 . 1 7, t e s t, H i   A n d y ,   B A C K   I N   B L A C K ,   w i e   w i r   d i c h   k e n n e n .   * g * <br>
1, 3, 1 0 5 5 1 5 9 1 7 8, 8 0 . 1 4 5 . 1 2 2 . 1 7, , s o   s i n d   s i e   h a l t ,   d i e   W I B <br>
</body></html>

Das Problem:
Erstmal wird er erste Wert falsch eingelesen "ÿþ1" statt "1".
Aber das viel größere Problem ist ja, dass hinter jedes Zeichen ein Leerzeichen gemacht wird, das da nicht hingehört. Kann sich das jemand erklären bevor ich noch verzweifle`?

Danke für eure Mühe.

Maike