示例#1
0
 function stripDebug($xml, &$stripped = '')
 {
     $tags = array('strong', 'pre');
     $tags_elems = array();
     foreach ($tags as $tag) {
         $tags_elems[$tag] = array('start' => '<(?<' . $tag . '_start>' . $tag . ')[^>]*?>', 'end' => '<\\/(?<' . $tag . '_end>' . $tag . ')>');
     }
     $reg = '/' . implode('|', set::flatten($tags_elems)) . '/sim';
     $stack = 0;
     $offset = 0;
     $start = 0;
     while (preg_match($reg, $xml, $matches, PREG_OFFSET_CAPTURE, $offset)) {
         $matche = $this->qualifyMatch($matches);
         if ($matche['elem'] == 'start') {
             if ($stack == 0) {
                 $start = $matche['pos'];
             }
             $stack++;
         } else {
             $stack--;
             if ($stack == 0) {
                 $end = $matche['pos'] + strlen($matche['string']);
                 $stripped .= substr($xml, $start, $end - $start);
                 $xml = substr($xml, 0, $start) . substr($xml, $end);
                 $offset -= $end - $start;
                 continue;
             }
         }
         $offset = $matche['pos'] + strlen($matche['string']);
     }
     return $xml;
 }