1. Go to this page and download the library: Download fivefilters/readability.php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fivefilters / readability.php example snippets
ivefilters\Readability\Readability;
use fivefilters\Readability\ParseException;
$readability = new Readability();
$html = file_get_contents('https://your.favorite.newspaper/article.html');
try {
$article = $readability->parse($html);
if ($article->hasContent()) {
echo $article->content;
} else {
// no article content found — title and metadata are still available
echo sprintf('No content found in "%s"', $article->title);
}
} catch (ParseException $e) {
echo sprintf('Error processing text: %s', $e->getMessage());
}
$article->title; // string – article title
$article->content; // string – processed article HTML
$article->textContent; // string – article text with all HTML removed
$article->length; // int – length of textContent in characters
$article->excerpt; // ?string – description or short excerpt
$article->byline; // ?string – author metadata
$article->siteName; // ?string – name of the site
$article->dir; // ?string – content direction (ltr/rtl)
$article->lang; // ?string – content language
$article->publishedTime; // ?string – published time
$article->image; // ?string – lead image URL (og:image/twitter:image/link)
$article->images; // string[] – lead image + all content images, de-duplicated
$article->contentElement; // \Dom\Element – content as a DOM element
echo $article; // same as $article->content
<h1><?= $article->title
foreach ($article->contentElement->querySelectorAll('img[src]') as $img) {
$images[] = $img->getAttribute('src');
}
use fivefilters\Readability\Readerable;
// Only run the full parse if we suspect it will produce a meaningful result.
if (Readerable::isProbablyReaderable($html)) {
$article = new Readability()->parse($html);
}
$readability = new Readability(
fixRelativeURLs: true,
originalURL: 'https://my.newspaper.url/article/something-interesting-to-read.html',
);
use fivefilters\Readability\Configuration;
$configuration = new Configuration(fixRelativeURLs: true, originalURL: 'https://...');
$readability = new Readability($configuration);
bash
cd test/tools && npm install
node cross-check.mjs
php cross-check.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.