You are here

function xbbcode_list_split_items in Extensible BBCode 5

Same name and namespace in other branches
  1. 6 xbbcode_list/xbbcode_list.module \xbbcode_list_split_items()
1 call to xbbcode_list_split_items()
xbbcode_list_render in xbbcode_list/xbbcode_list.module

File

xbbcode_list/xbbcode_list.module, line 45

Code

function xbbcode_list_split_items($text, $level = 1) {
  $items = preg_split('/\\[\\*{' . $level . ',' . $level . '}\\]/', $text);
  foreach ($items as $i => $item) {
    $items[$i] = trim($item);
  }
  if (count($items) > 1) {
    $parent = array_shift($items);
  }
  foreach ($items as $i => $item) {
    if (preg_match('/\\[\\*{' . ($level + 1) . ',' . ($level + 1) . '}\\]/', $item)) {
      $items[$i] = xbbcode_list_split_items($item, $level + 1);
    }
  }
  $items['#parent'] = $parent;
  return $items;
}