Jörg: Warum kommen hier unterschiedliche Ergebnisse raus?

Beitrag lesen

Script:

<?php

// Text einlesen
$text = "[size=3][b]BBCode SCEditor[/b][/size]

Give it a try! :)

[color=#ff00]Red text! [/color][color=#3399ff]Blue?[/color]

[ul]
[li]A simple list[/li]
[li]list item 2[/li]
[/ul]

If you are u[font=Comic Sans MS]sing IE9+[/font] or any non-IE browser just type [b]:[/b]) and it should be heriuhg3r  www.test.de oder aber auch [url=test.de]test.de[/url] converted into :) as you type.

[table][tr][td]wrtz4z[/td]
[td][/td]
[/tr]
[tr][td][/td]
[td]dzerh[/td]
[/tr]
[/table]";

# Zeilenumbrüche korrigieren
$text = str_replace("\r\n","\n",$text); # windows -> linux
$text = str_replace("\r","\n",$text); # mac -> linux

# array bilden
$arr_text = explode("\n",$text);
$neuerText = '';

foreach($arr_text as $zeile) {

    if (preg_match("/\[\/?(li|ul|td|tr|table|code|quote|list|ol)\]$/",$zeile)) {
        $zeile = str_replace("\n", "", $zeile);
       echo $zeile;
    } else {
        echo $zeile."<br>";
    }

   $neuerText .= $zeile;

}

echo "<hr>".nl2br($neuerText);

Ergebnis:

Jörg