Example #1
0
 /**
  * Parse the specified text for BB codes and return the syntax tree.
  *
  * @param string $text
  *
  * @return array
  */
 public function parse($text)
 {
     $this->_resetParser();
     $text = $this->_formatter->preFilterText($text);
     $this->_text = $text;
     $length = strlen($text);
     while ($this->_position < $length) {
         $success = $this->_parseTag();
         if (!$success) {
             $this->_pushText(substr($this->_text, $this->_position));
             $this->_position = $length;
             break;
         }
     }
     $this->_mergeTrailingText();
     $tree = $this->_tree;
     $this->_tree = array();
     $this->_tagStack = array();
     unset($this->_context);
     $this->_context = null;
     // break reference
     return $tree;
 }