PHP - how to get main HTML content like Reader Mode in Firefox

前端 未结 5 1986
无人共我
无人共我 2021-02-11 06:33

in android Firefox app and safari iPad we can read only main content by \"Reader Mode\". read more... How to recognize only main content in HTML with PHP?

I need to dete

5条回答
  •  一向
    一向 (楼主)
    2021-02-11 06:47

    Hooray!!!

    I found this source code:

    1) create Readability.php

    2) create JSLikeHTMLElement.php

    3) create index.php by this code:

    
    
        
            !
            
        
    
    cleanRepair();
        $html = $tidy->value;
    }
    
    // give it to Readability
    $readability = new Readability($html, $url);
    // print debug output? 
    // useful to compare against Arc90's original JS version - 
    // simply click the bookmarklet with FireBug's console window open
    $readability->debug = false;
    // convert links to footnotes?
    $readability->convertLinksToFootnotes = true;
    // process it
    $result = $readability->init();
    // does it look like we found what we wanted?
    if ($result) {
        echo "== Title =====================================\n";
        echo $readability->getTitle()->textContent, "\n\n";
        echo "== Body ======================================\n";
        $content = $readability->getContent()->innerHTML;
        // if we've got Tidy, let's clean it up for output
        if (function_exists('tidy_parse_string')) {
            $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
            $tidy->cleanRepair();
            $content = $tidy->value;
        }
        echo $content;
    } else {
        echo 'Looks like we couldn\'t find the content. :(';
    }
    ?>
    
    
    

    in $url = 'http://'; set your site url.

    Thank you;)

提交回复
热议问题