<?php $bbcode = <<<BBCODE [b]Check out this demo[/b] ¯\_(ツ)_/¯ [table] [**]header1[||]header2[||]header3[||]...[/**] [*]child1.1[|]child1.2[|]child1.3[|]... [*]child2.1[|]child2.2[|]child2.3[|]... [*]child3.1[|]child3.2[|]child3.3[|]... [*]...[|]...[|]...[|]... [/table] simple text [table] [**]a 1[||]and a 2[/**] [*]A[|]B [*]C[|]D [/table] [s]3, you're out[/s] blah BBCODE; function BBTableToHTML($m) { return "<table class=\"ui compact stripet yellow table\">\n" . preg_replace_callback_array( [ '~\[\*\*]([^[]*(?:\[(?!/?\*\*])[^[]*)*)\[/\*\*]~' => 'BBTHeadToHTML', '~(?:\[\*].*\R*)+~' => 'BBTBodyToHTML', '~\[\*](.*)~' => 'BBTBodyRowToHTML' ], $m[1] ) . "</table>"; } function BBTHeadToHTML($m) { return "\t<thead>\n" . "\t\t<tr>\n\t\t\t<th>" . str_replace('[||]', "</th>\n\t\t\t<th>", $m[1]) . "</th>\n\t\t</tr>\n" . "\t</thead>"; } function BBTBodyToHTML($m) { return "\t<tbody>\n{$m[0]}\t</tbody>\n"; } function BBTBodyRowToHTML($m) { return "\t\t<tr>\n\t\t\t<td>" . str_replace('[|]', "</td>\n\t\t\t<td>", $m[1]) . "</td>\n\t\t</tr>"; } echo preg_replace_callback( '~\[table]\R*([^[]*(?:\[(?!/?table])[^[]*)*)\R*\[/table]~', 'BBTableToHTML', $bbcode );
You have javascript disabled. You will not be able to edit any code.