GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - PressForward/PressForward-Readability: Arc90's Readability ported to PHP for FiveFilters.org and then updated for PressForward

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
JSLikeHTMLElement.php
JSLikeHTMLElement.php
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Readability.php
Readability.php
 
 
composer.json
composer.json
 
 

Repository files navigation

PHP Readability

This is a PHP port of Arc90's original Javascript version of Readability. (Arc90 has since relaunched the project.)

For instructions on how to use this, please see http://www.keyvan.net/2010/08/php-readability/

This library has been updated for the PressForward project by the Roy Rosenzweig Center for History and New Media at George Mason University, through the Generous Support of the Alfred P. Sloan Foundation.

It was updated and continues to be maintained with the goal of allowing maximum use on a changing modern web.

  • More information about PressForward: http://pressforward.org/
  • This project lives on: https://github.com/PressForward/PressForward-Readability

For a more flexible and robust solution to article extraction, take a look at Full-Text RSS - it makes use of PHP Readability, but offers much more.

Feel free to fork this and change/improve it. I would love to see your results. Please do share them and I'll consider pulling them in.

PHP Readability is licensed under the Apache License, Version 2.0 (the same license as the original JS version). The original Javascript version can be found here: http://code.google.com/p/arc90labs-readability/source/browse/ (readability.js)

Simple example

<?php
require_once 'readability/Readability.php';
header('Content-Type: text/plain; charset=utf-8');

// get latest Medialens alert 
// (change this URL to whatever you'd like to test)
$url = 'http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/729-thatcher.html';
$html = file_get_contents($url);

// Note: PHP Readability expects UTF-8 encoded content.
// If your content is not UTF-8 encoded, convert it 
// first before passing it to PHP Readability. 
// Both iconv() and mb_convert_encoding() can do this.

// If we've got Tidy, let's clean up input.
// This step is highly recommended - PHP's default HTML parser
// often doesn't do a great job and results in strange output.
if (function_exists('tidy_parse_string')) {
	$tidy = tidy_parse_string($html, array(), 'UTF8');
	$tidy->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. :(';
}

About

Arc90's Readability ported to PHP for FiveFilters.org and then updated for PressForward

Resources

Readme
License
Activity
Custom properties

Stars

4 stars

Watchers

13 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.