009
10.01.2005, 17:26 Uhr
Pablo
Supertux (Operator)
|
Ach so, ein Board Code. Das ist nicht schwer, ich benutze dafür preg_replace dafür.
PHP 4: |
<?php
function parse_content($content, $htmlent=1) {
global $lang, $http_tpl_dir;
/* ok, we are going to use regular expression to parse the contents. If htmlent is 1 htmlentities will be used for the whole content before the content is parsed */
$quote_von = array('de' => 'Zitat von', 'en' => 'Quote from', 'es' => 'Cita de'); $quote = array('de' => 'Zitat', 'en' => 'Quote', 'es' => 'Cita');
if($htmlent) $content = htmlentities($content);
$reg1 = array( "/\[b\](.*)(\[\/b\])/Us", "/\[i\](.*)(\[\/i\])/Us", "/\[u\](.*)(\[\/u\])/Us", "/\[\-\](.*)(\[\/\-\])/Us", "/\[url=(.*)](.*)(\[\/url\])/Us", "/\[url]http:\/\/(.*)(\[\/url\])/Us", "/\[url](.*)(\[\/url\])/Us", "/\[img\](.*)(\[\/img\])/Us", "/\[mail\](.*)(\[\/mail\])/Us", "/\[mail=(.*)\](.*)(\[\/mail\])/Us", "/\[color=(.*)\](.*)(\[\/color\])/Us", "/\[size=(.*)\](.*)(\[\/size\])/Us"
);
$chg1 = array( "<b>\\1</b>", "<i>\\1</i>", "<u>\\1</u>", "<s>\\1</s>", "<a href=\"\\1\" target=\"_blank\">\\2</a>", "<a href=\"http://\\1\" target=\"_blank\">http://\\1</a>", "<a href=\"http://\\1\" target=\"_blank\">http://\\1</a>", "<img src=\"\\1\" alt=\"\" />", "<a href=\"mailto:\\1\">\\1</a>", "<a href=\"mailto:\\1\">\\2</a>", "<span style=\"color: \\1;\">\\2</span>", "<span style=\"font-size: \\1pt;\">\\2</span>"
);
/* here we parse tags like [code], [quote], etc */
$reg = array( "/\[code\](.*)(\[\/code\])/Use", "/\[code (.*)\](.*)(\[\/code\])/Use", "/\[php\](.*)(\[\/php\])/Use", "/\[quote\](.*)(\[\/quote\])/Use", "/\[quote (.*)\](.*)(\[\/quote\])/Use", "/\[cpp\](.*)(\[\/cpp\])/Use" );
$chg = array( "table_parse('<code><br />' . trim('\\1') . '<br /> </code>', 'Code: ')", "table_parse('<code><br />' . trim('\\2') . '<br /> </code>', '\\1: ')", //"table_parse('<br />' . parse_PHP(reverse_htmlentities(trim('\\1'))) . '<br /> ', 'PHP Code: ')", "table_parse(highlight_string(reverse_htmlentities(trim('\\1')),TRUE), 'PHP Code')", "table_parse('<br />' . trim('\\1') . '<br /> ','$quote[$lang]: ')", "table_parse('<br />' . trim('\\2') . '<br /> ','$quote_von[$lang] \\1: ')", "table_parse('<br />' . parse_C(reverse_htmlentities(trim('\\1'))) . '<br /> ', 'C/C++ Code: ')" );
/* " " --> and \n --> <br /> */
$reg2 = array( "/ /", "/\r/", "/\n/", "/\t/" ); $chg2 = array( " ", "", "<br />", " " );
$reg = array_merge($reg, $reg1, $reg2); $chg = array_merge($chg, $chg1, $chg2);
$content = preg_replace($reg, $chg, $content);
return $content; } ?>
|
wobei table_parse eine Funktion ist, die eine Tabelle um den Text erstellt.
So funktioniert bis jetzt einigermassen in Ordnung, arbeite grad an etwas besserem. -- A! Elbereth Gilthoniel! silivren penna míriel o menel aglar elenath, Gilthoniel, A! Elbereth! Dieser Post wurde am 10.01.2005 um 17:30 Uhr von Pablo editiert. |