Falcon_Converter::convert PHP Метод

convert() публичный Метод

Convert HTML into a textual representation
public convert ( ) : string
Результат string Text representation
    public function convert()
    {
        if (!empty($this->text)) {
            return $this->text;
        }
        $html = $this->preprocess($this->html);
        $this->document = new DOMDocument();
        set_error_handler(array(__CLASS__, 'silence_errors'));
        $this->document->loadHTML($html);
        restore_error_handler();
        // Remove the DOCTYPE
        // Seems to cause segfaulting if we don't do this
        if ($this->document->firstChild instanceof DOMDocumentType) {
            $this->document->removeChild($this->document->firstChild);
        }
        $this->text = $this->parse_children($this->document->getElementsByTagName('body')->item(0));
        $this->text = preg_replace("#\n{3,}#", "\n\n", $this->text);
        $this->text = $this->wrap($this->text, 80);
        $this->text .= $this->generate_links();
        return $this->text;
    }

Usage Example

Пример #1
0
 /**
  * Convert the post content to text
  *
  * @wp-filter bbsub_html_to_text
  * @param string $html HTML to convert
  * @return string Text version of the content
  */
 public static function convert_html_to_text($html)
 {
     $converter = new Falcon_Converter($html);
     return $converter->convert();
 }