HTMLPurifier_Lexer::extractBody PHP Method

extractBody() public method

Takes a string of HTML (fragment or document) and returns the content
public extractBody ( $html )
    public function extractBody($html)
    {
        $matches = array();
        $result = preg_match('|(.*?)<body[^>]*>(.*)</body>|is', $html, $matches);
        if ($result) {
            // Make sure it's not in a comment
            $comment_start = strrpos($matches[1], '<!--');
            $comment_end = strrpos($matches[1], '-->');
            if ($comment_start === false || $comment_end !== false && $comment_end > $comment_start) {
                return $matches[2];
            }
        }
        return $html;
    }

Usage Example

Beispiel #1
0
 function assertExtractBody($text, $extract = true)
 {
     $lexer = new HTMLPurifier_Lexer();
     $result = $lexer->extractBody($text);
     if ($extract === true) {
         $extract = $text;
     }
     $this->assertIdentical($extract, $result);
 }