Page 1 of 1

bbcode> creating tables

Posted: Sat Mar 08, 2003 6:03 pm
by ArgoNaut_Iron
for some reason i can't create a simple table like
<table width="100%">

in a post. it shows 5 blank rules above the table. is it possible to make a working "table tag" with bbcode?

tnx in advance

Posted: Sun Mar 09, 2003 12:03 am
by talia679
I would love the ability to have tables ... this is a mod I would use!

Posted: Sun Mar 09, 2003 7:34 am
by LifeIsPain
Well, it is possible, I have it worked out except for the fact that it doesn't use extra variables (for now) and it is really easy to mess up. So in order to use it, you have to be pretty specific, and extra characters are not liked. Note that I woked on this from a modification of bbcode.php that doesn't use templates, is split up into multiple files, but I will give the code changes I made if someone wants to run with it, and will also say what I think the code would have been with a standard install (not testing). Also please note that I am no longer using this code, I left behind for a different method (one where tables aren't in the code, that is left to my page layout)

Code: Select all

#-----[ OPEN ]------------

#------[ FIND ]--------------
	// ordered.
	$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]",  false, 'replace_listitems');

#------[ AFTER, ADD ]-------------------
	// [table] and [/table] for adding tables. Smart enough to know that it must be
	// nested correctly
	$text = bbencode_first_pass_pda($text, $uid, '[table]', '[/table]', '', false, 'replace_tablerows');

#------[ FIND ]--------------
	// [center] and [/center] for centering content
	$text = str_replace("[center:$uid]", $bbcode_tpl['center_open'], $text);
	$text = str_replace("[/center:$uid]", $bbcode_tpl['center_close'], $text);

#------[ AFTER, ADD ]-------------------
	// [table] and [/table] for tables
	$text = str_replace("[table:$uid]", $bbcode_tpl['table_open'], $text);
	$text = str_replace("[/table:$uid]", $bbcode_tpl['table_close'], $text);

	// [tr] and [/tr] for table rows
	$text = str_replace("[tr:$uid]", $bbcode_tpl['tr_open'], $text);
	$text = str_replace("[/tr:$uid]\r\n", $bbcode_tpl['tr_close'], $text);
	$text = str_replace("[/tr:$uid]", $bbcode_tpl['tr_close'], $text);

	// [td] and [/td] for table cells
	$text = str_replace("[td:$uid]", $bbcode_tpl['td_open'], $text);
	$text = str_replace("[/td:$uid]\r\n", $bbcode_tpl['td_close'], $text);
	$text = str_replace("[/td:$uid]", $bbcode_tpl['td_close'], $text);

#------[ FIND ]--------------
function replace_listitems($text, $uid)
	$text = str_replace("[*]", "[*:$uid]", $text);

	return $text;

#------[ AFTER, ADD ]--------------------
function replace_tablerows($text, $uid)
	$text = substr(bbencode_first_pass_pda(' '.$text, $uid, '[tr]', '[/tr]', '', false, 'replace_tablecells'), 1);

	return $text;

function replace_tablecells($text, $uid)
	$text = substr(bbencode_first_pass_pda(' '.$text, $uid, '[td]', '[/td]', '', false, ''), 1);

	return $text;

#------[ OPEN ]---------------

#------[ FIND ]---------------
<!-- BEGIN listitem --><li><!-- END listitem -->

#------[ AFTER, ADD ]--------------
<!-- BEGIN table_open --><table><!-- END table_open -->
<!-- BEGIN table_close --></table><!-- END table_close -->

<!-- BEGIN tr_open --><tr><!-- END tr_open -->
<!-- BEGIN tr_close --></tr><!-- END tr_close -->

<!-- BEGIN td_open --><td><!-- END td_open -->
<!-- BEGIN td_close --></td><!-- END td_close -->

#------[ EOF ]-----------------
Ok, now to let you in a few of my problems. I was unable to get it to ignore bad calls such as:

Code: Select all

[table]bob is cool[tr][td]stuff[/td][/tr]
or other times where text is outside of the table rows, table cells that don't exist, but it is still accepted. But if you use good bbcode, the table works fine (oh, and don't use a line break after an opening comment, you get a bunch of blank lines). But if someone is able to run with the above, that is great.