Hi,
ich rege mich gerade zum fünftausends Mal über Regular Expressions bei PHP auf.
Das Problem ist folgendes: auf
dieser Seite sieht man, dass der SourceCode keinerlei Umbrüche hat. Bei mir auf dem
Localhost funktioniert jedoch alles problemlos.

Dort wird alles korrekt umgebrochen.
Ich parse so die Datei für die Ausgabe:
Code:
foreach($lines as $line) {
if (strpos($line, "<body") !== false) {
$print = true;
} elseif (strpos($line, "</body>") !== false) {
$print = false;
} elseif ($print) {
if (preg_match("|###include \"(.*?)\" \/###|is", $line)) {
$line = preg_replace("|###include \"(.*?)\" \/###|is", "require \"".$cwd."/scripts/siteincludes/\\1\";", $line);
eval($line);
} elseif(preg_match("|###variable \"(.*?)\" \/###|is", $line)) {
$line = preg_replace("|###variable \"(.*?)\" \/###|is", "echo \\1;", $line);
eval($line);
} elseif(preg_match("|###setvar \"(.*?)\" \"(.*?)\" \/###|is", $line)) {
$line = preg_replace("|###setvar \"(.*?)\" \"(.*?)\" \/###|is", "\\1 = \"\\2\";", $line);
eval($line);
} else {
// $line = preg_replace("|\w\<a href=\"\w(\&)\w\"\>\w|is", "\&", $line);
print $line;
}
}
($lines ist das Array mit dem Inhalt der zu parsenden Datei)
Das Problem ist jedoch in meinen selbst gebauten BBCodes:
Code:
function parseBBCode($text, $urls = true) {
global $wrkdir;
$match = array();
$replace = array();
if ($urls) {
// matches [
url]http://www.csd-software.net[/
url]
$match[] = '#(^|[\n ])([\w]+?://(.*?)[^ \t\n\r<"]*)#ie';
$replace[] = "'\\1<a href=\"\\2\" target=\"_blank\">' . ((strlen('\\2') > 40) ? substr('\\2', 0, 20) . ' ... ' . substr('\\2', -20) : '\\2') . '</a>'";
// matches [
url]www.csd-software.net[/
url]
$match[] = '#(^|[\n ])((www|
ftp)(.*?)[^ \t\n\r<"]*)#ie';
$replace[] = "'\\1<a href=\"http://\\2\" target=\"_blank\">' . ((strlen('\\2') > 40) ? substr('\\2', 0, 20) . ' ... ' . substr('\\2', -20) : '\\2') . '</a>'";
}
// matches [
url]http://www.csd-software.net[/
url]
$match[] = '#\[
url\](.*?)\[\/
url\]#ie';
$replace[] = "'<img src=\"".$wrkdir."images/link.gif\" border=\"0\"> <a href=\"\\1\" target=\"_blank\">' . ((strlen('\\1') > 40) ? substr('\\1', 0, 20) . ' ... ' . substr('\\1', -20) : '\\1') . '</a>'";
// matches [
url=http://www.csd-software.net]Text[/
url]
$match[] = '#\[
url=(.*?)\](.*?)\[\/
url\]#i';
$replace[] = '<img src=\"'.$wrkdir.'images/link.gif\" border=\"0\"> [
url="\\1"]\\2[/
url]';
// matches [b]Text[/b]
$match[] = '#\[b\](.*?)\[\/b\]#i';
$replace[] = '[b]\\1[/b]';
// matches [i]Text[/i]
$match[] = '#\[i\](.*?)\[\/i\]#i';
$replace[] = '[i]\\1[/i]';
// matches [u]Text[/u]
$match[] = '#\[u\](.*?)\[\/u\]#i';
$replace[] = '<u>\\1</u>';
// matches [quote=From]Quotation[/quote]
$match[] = '#\[quote=(.*?)\]((.|\n)*?)\[\/quote\]#i';
$replace[] = '<p class="QuoteTitle">[size="1"][b]\\1:[/b][/size]</p><p class="QuoteText">\\2</p>';
// matches [quote]Quotation[/quote]
$match[] = '#\[quote\]((.|\n)*?)\[\/quote\]#i';
$replace[] = '<p class="QuoteTitle">[size="1"][b]Zitat:[/b][/size]</p><p class="QuoteText">\\1</p>';
// matches [code]SourceCode
$match[] = '#\[code\]((.|\n)*?)\[\/code\]#ie';
$replace[] = "'<p class=\"QuoteTitle\">[size="1"]
Code:[/size]</p><pre class=\"SourceText\">' . br2nl(stripslashes('\\1')) . '</pre>'";
// matches
PHP-SourceCode
$match[] = '#\[php\]((.|\n)*?)\[\/php\]#ie';
$replace[] = "'<p class=\"QuoteTitle\">[size="1"]
Code:[/size]</p><p class=\"SourceText\">' . highlight_string(stripslashes(br2nl('\\1')),true) . '</p>'";
$text = preg_replace($match, $replace, $text);
return $text;
}
// und noch die Funktion für den Umbruch
function br2nl($text) {
$match = '#(^|[\n ])<br(.*?)>[^ \t\n\r<"]#ie';
$replace = '\n';
$ret = preg_replace($match, $replace, $text);
return $ret;
}[/code]
Woran kann es jetzt also liegen, dass PHP auf meinem lokalen Webspace alles richtig macht, online jedoch keinerlei Zeilenumbrüche vornimmt?
Chris