I have the following code in a news script which i made (as an add-on for phpbb2) however i wish to move it out of the main script and into another file which deals with all the BB code...
// [list] and [list=x] for (un)ordered lists.
// unordered lists
$text = str_replace("[list:$bbcode_uid]", $bbcode_tpl['ulist_open'], $text);
// li tags
$text = str_replace("[*:$bbcode_uid]", $bbcode_tpl['listitem'], $text);
// ending tags
$text = str_replace("[/list:u:$bbcode_uid]", $bbcode_tpl['ulist_close'], $text);
$text = str_replace("[/list:o:$bbcode_uid]", $bbcode_tpl['olist_close'], $text);
// Ordered lists
$text = preg_replace("/\[list=([a1]):$bbcode_uid\]/si", $bbcode_tpl['olist_open'], $text);
// Quotes
$text = str_replace ("[code:$bbcode_uid]", $bbcode_tpl['code_open'], $text);
$text = str_replace ("[/code:$bbcode_uid]", $bbcode_tpl['code_close'], $text);
// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$bbcode_uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);
// Code
$text = str_replace ("[quote:$bbcode_uid]", $bbcode_tpl['quote_open'], $text);
$text = str_replace ("[/quote:$bbcode_uid]", $bbcode_tpl['quote_close'], $text);
// [b] and [/b] for bolding text.
$text = str_replace("[b:$bbcode_uid]", $bbcode_tpl['b_open'], $text);
$text = str_replace("[/b:$bbcode_uid]", $bbcode_tpl['b_close'], $text);
// [u] and [/u] for underlining text.
$text = str_replace("[u:$bbcode_uid]", $bbcode_tpl['u_open'], $text);
$text = str_replace("[/u:$bbcode_uid]", $bbcode_tpl['u_close'], $text);
// [i] and [/i] for italicizing text.
$text = str_replace("[i:$bbcode_uid]", $bbcode_tpl['i_open'], $text);
$text = str_replace("[/i:$bbcode_uid]", $bbcode_tpl['i_close'], $text);
// size
$text = preg_replace("/\[size=([1-2]?[0-9]):$bbcode_uid\]/si", $bbcode_tpl['size_open'], $text);
$text = str_replace("[/size:$bbcode_uid]", $bbcode_tpl['size_close'], $text);
// colours
$text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$bbcode_uid\]/si", $bbcode_tpl['color_open'], $text);
$text = str_replace("[/color:$bbcode_uid]", $bbcode_tpl['color_close'], $text);
however, my only problem is, that to make it a function, at my current knowledge, ill need to manually insert every $bbcode_tpl['xxx'] into it...
how could i alter the making of the $bbcode_tpl variables in order so $bbcode_tpl would carry them all.... like the return of a mysql result.
The code which makes it is:
$bbcode_tpl['quote_open'] = extract_code('QUOTE_START', $code_template);
$bbcode_tpl['quote_close'] = extract_code('QUOTE_END', $code_template);
$bbcode_tpl['quote_username_open'] = extract_code('QUOTE_USERNAME', $code_template);
$bbcode_tpl['b_open'] = extract_code('B_START', $code_template);
$bbcode_tpl['b_close'] = extract_code('B_END', $code_template);
$bbcode_tpl['u_open'] = extract_code('U_START', $code_template);
$bbcode_tpl['u_close'] = extract_code('U_END', $code_template);
$bbcode_tpl['i_open'] = extract_code('I_START', $code_template);
$bbcode_tpl['i_close'] = extract_code('I_END', $code_template);
$bbcode_tpl['size_open'] = extract_code('SIZE_START', $code_template);
$bbcode_tpl['size_close'] = extract_code('SIZE_END', $code_template);
etc etc
any help would be greatly appreciated!
I assume i need to turn it into an array, but i have no idea how to properly!