Ejemplo n.º 1
0
 /**
  * @param string $text
  * @param array $tags
  * @param int $level
  * @param int $offset
  */
 public static function create($text, $tags = null, $level = 0, $offset = 0)
 {
     $instance = new PhpFit_Parse();
     if ($tags == null) {
         $tags = PhpFit_Parse::$tags;
     }
     $startTag = stripos($text, '<' . $tags[$level]);
     $endTag = stripos($text, '>', $startTag) + 1;
     $startEnd = stripos($text, '</' . $tags[$level], $endTag);
     $endEnd = stripos($text, '>', $startEnd) + 1;
     $startMore = stripos($text, '<' . $tags[$level], $endEnd);
     if ($startTag === false || $endTag === false || $startEnd === false || $endEnd === false) {
         throw new PHPFit_Exception_Parse('Can\'t find tag: ' . $tags[$level], $offset);
     }
     $instance->leader = substr($text, 0, $startTag);
     $instance->tag = substr($text, $startTag, $endTag - $startTag);
     $instance->body = substr($text, $endTag, $startEnd - $endTag);
     $instance->end = substr($text, $startEnd, $endEnd - $startEnd);
     $instance->trailer = substr($text, $endEnd);
     // we are not at cell-level, so dig further down
     if ($level + 1 < count($tags)) {
         $instance->parts = PhpFit_Parse::create($instance->body, $tags, $level + 1, $offset + $endTag);
         $instance->body = null;
     }
     // if you have more of the same
     if ($startMore !== false) {
         $instance->more = PhpFit_Parse::create($instance->trailer, $tags, $level, $offset + $endEnd);
         $instance->trailer = null;
     }
     return $instance;
 }
Ejemplo n.º 2
0
 public function testFractBody()
 {
     $p = PhpFit_Parse::create('leader<Table foo=2>0.5</table>trailer', array('table'));
     $this->assertEquals('leader', $p->leader);
     $this->assertEquals('<Table foo=2>', $p->tag);
     $this->assertEquals('0.5', $p->text());
     $this->assertEquals('trailer', $p->trailer);
 }