Ejemplo n.º 1
0
 /**
  * Return text as one string
  *
  * @return string
  *
  * @since 1.2
  */
 public function getAsString()
 {
     $text = parent::getAsString();
     $stripAll = new StripAllFilter();
     $htmlFilter = new HtmlFilter();
     /* Removing CDATA tags */
     $text = preg_replace_callback('#<!\\[CDATA\\[(.*?)\\]\\]>#ums', function ($match) use($htmlFilter) {
         $string = $htmlFilter->filter($match[1]);
         //      <![CDATA[               ]]
         return '         ' . $string . '  ';
     }, $text);
     /* Processing bottom level tags */
     $text = preg_replace_callback('#(<(\\w+)(\\s[^>]*?)?>)([^<>]*)(</\\w+\\s*>)#um', function ($match) use($stripAll) {
         if (strtolower($match[2]) === 'target') {
             $replace = $stripAll->filter($match[1]) . $match[4] . $stripAll->filter($match[5]);
         } else {
             $replace = $stripAll->filter($match[0]);
         }
         return $replace;
     }, $text);
     /* Other replacements */
     foreach ($this->filters as $pattern => $filter) {
         if (null === $filter) {
             $filter = $stripAll;
         }
         $text = preg_replace_callback($pattern, function ($match) use($filter) {
             return $filter->filter($match[0]);
         }, $text);
     }
     return $text;
 }
Ejemplo n.º 2
0
 /**
  * Test basic functional
  */
 public function testBasics()
 {
     $filter = new StripAllFilter();
     static::assertEquals("   \n\t   ", $filter->filter("foo\n\tbar"));
 }