先來看一下範例
正常的:
代碼: 選擇全部
[list=1][*]111
[list][*]aaa[/list]
[*]222[/list]- 111
- aaa
- 222
代碼: 選擇全部
[list][*]111
[list=1][*]aaa[/list]
[*]222[/list]- 111
- aaa
- 222
針對 list bbcode 判斷上的錯誤, 個人做了底下的修正
目前的測試結果都很正常, 提供給大家參考參考
#
#--------[ OPEN ]----------------
#
includes/bbcode.php
#
#--------[ FIND ]----------------
#
代碼: 選擇全部
$open_tag = array();
$open_tag[0] = "[list]";
// unordered..
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');
$open_tag[0] = "[list=1]";
$open_tag[1] = "[list=a]";
// ordered.
$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');#--------[ REPLACE WITH ]----------------
#
代碼: 選擇全部
/** $open_tag = array();
* $open_tag[0] = "[list]";
*
* // unordered..
* $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems');
*
* $open_tag[0] = "[list=1]";
* $open_tag[1] = "[list=a]";
*
* // ordered.
* $text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems');
*/
if (preg_match("/\[list(=[a1])?\]/si", $text))
{
$text = bbencode_list_pass($text, $uid);
}#--------[ FIND ]----------------
#
代碼: 選擇全部
?>#--------[ BEFORE, ADD ]----------------
#
代碼: 選擇全部
function bbencode_list_pass($text, $uid)
{
$text = preg_replace("#\[list(=[a1])?\]#si", "[list\\1:$uid]", $text);
$curr_pos = 1;
$open_arry = Array();
while ($curr_pos && ($curr_pos < strlen($text)))
{
$list_type = '';
$curr_pos = strpos($text, "[", $curr_pos);
if ($curr_pos)
{
$possible_tag = substr($text, $curr_pos, strpos($text, ']', $curr_pos + 1) - $curr_pos + 1);
if (strcasecmp($possible_tag, "[list:$uid]") == 0)
{
array_push($open_arry, 'u');
}
elseif (strcasecmp($possible_tag, "[list=1:$uid]") == 0 || strcasecmp($possible_tag, "[list=a:$uid]") == 0)
{
array_push($open_arry, 'o');
}
elseif (strcasecmp($possible_tag, '[/list]') == 0)
{
$list_type = array_pop($open_arry);
$text = substr_replace($text, "[/list:$list_type:$uid]", $curr_pos, strlen($possible_tag));
$curr_pos += strlen($possible_tag);
} else {
++$curr_pos;
continue;
}
$curr_pos += strlen($possible_tag);
}
}
$text = replace_listitems($text, $uid);
return $text;
}#--------[ SAVE/CLOSE FILE ]----------------
#
# EoM



