![]() |
PREG funktioniert nur lokal
Hi,
ich rege mich gerade zum fünftausends Mal über Regular Expressions bei PHP auf. Das Problem ist folgendes: auf ![]() Dort wird alles korrekt umgebrochen. Ich parse so die Datei für die Ausgabe:
Code:
($lines ist das Array mit dem Inhalt der zu parsenden Datei)
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; } } Das Problem ist jedoch in meinen selbst gebauten BBCodes:
Code:
$match[] = '#\[code\]((.|\n)*?)\[\/code\]#ie';
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 $replace[] = "'<p class=\"QuoteTitle\">[size="1"]Code:[/size]</p><pre class=\"SourceText\">' . br2nl(stripslashes('\\1')) . '</pre>'"; // matches
PHP-Quellcode:
$match[] = '#\[php\]((.|\n)*?)\[\/php\]#ie';
PHP-SourceCode
$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 |
Re: PREG funktioniert nur lokal
Zitat:
|
Re: PREG funktioniert nur lokal
Hi,
hm... mir würde jetzt nicht einfallen, wo ich das beachte. ;) Wenn du mir kurz erklären könntest, wie ich das ändern muss. ;) Chris |
Re: PREG funktioniert nur lokal
Ich hab mich wohl geirrt. Auf meinem System funktioniert es weder mit einem durch '\n' noch mit einem durch '\r\n' umgebrochenen String (GNU/Linux mit PHP 4.3.6).
|
Re: PREG funktioniert nur lokal
Hi,
lokal: PHP 4.3.4 online: PHP 4.3.1 ;) Chris |
Re: PREG funktioniert nur lokal
Daran muss es nicht liegen. Ich habe auf bugs.php.org/ keinen entsprechenden Bug gefunden und auch im Manual bei preg_replace() findet sich kein Hinweis, dass sich was geändert haben könnte. Und wie gesagt, bei mir mit PHP 4.3.6 funktioniert es nicht.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz