标题:类TeX的UBB表格函数 出处:Felix021 时间:Thu, 19 Nov 2009 02:29:49 +0000 作者:felix021 地址:https://www.felix021.com/blog/read.php?1766 内容: 引用 UBB内容为(开头那个下划线不需要加): [_table] l | r | l | c | r 左对齐|右对齐|左对齐|居中啦啦啦|右对齐 1|23|456|7890[newline]1234|0000 abcd|efg|hi|[-]|j 1|[-]|[-]|1|1 [/table] 效果: 左对齐 右对齐 左对齐 居中啦啦啦 右对齐 1 23 456 7890 1234 0000 abcd efg hi j 1 1 1 PHP代码: function maketbl($str) { $str = str_replace("
", "\n", $str); $str = str_replace("|", "|", $str); $str = trim($str); $lines = explode("\n", $str); $firstline = explode("|", trim($lines[0])); $conf = array(); foreach($firstline as $v) { switch($v) { case 'l': $conf[] = 'left'; break; case 'r': $conf[] = 'right'; break; case 'c': $conf[] = 'center'; break; default: $conf[] = ''; } } $ncols = count($conf); $nline = count($lines); $ret = ''. "\n"; for ($i = 1; $i < $nline; $i++) { $line = trim($lines[$i]); if (empty($line)) continue; $line = explode("|", $line); $ret .= "\n"; $next = 1; for ($j = 0; $j < $ncols; $j++) { if ($line[$j] == "[-]") { $next++; continue; } $td = $line[$j]; //$td = htmlspecialchars($td); $td = str_replace("[newline]", "
", $td); $ret .= <<{$td} eot; if ($line[$j] != "[-]") { $next = 1; } } $ret .= "\n"; } $ret .= "
"; return $ret; } Generated by Bo-blog 2.1.0