mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 06:26:17 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# Readability
|
||||
|
||||
[](https://travis-ci.org/j0k3r/php-readability)
|
||||
|
||||
This is an extract of the Readability class from the [full-text-rss](https://github.com/Dither/full-text-rss) fork. It kind be defined as a better version of the original [php-readability](http://code.fivefilters.org/php-readability).
|
||||
|
||||
## Differences
|
||||
|
||||
The default php-readability lib is really old and needs to be improved. I found a great fork of [full-text-rss](http://fivefilters.org/content-only/) from @Dither which improve the Readability class.
|
||||
|
||||
- I've extracted the class from its fork to be able to use it out of the box
|
||||
- I've added some simple tests
|
||||
- and changed the CS, run `php-cs-fixer` and added a namespace
|
||||
|
||||
**But** the code is still really hard to understand / read ...
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
use Readability\Readability;
|
||||
|
||||
$url = 'http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/729-thatcher.html';
|
||||
|
||||
// you can use whatever you want to retrieve the html content (Guzzle, Buzz, cURL ...)
|
||||
$html = file_get_contents($url);
|
||||
|
||||
$readability = new Readability($html, $url);
|
||||
$result = $readability->init();
|
||||
|
||||
if ($result) {
|
||||
// display the title of the page
|
||||
echo $readability->getTitle()->textContent;
|
||||
// display the *readability* content
|
||||
echo $readability->getContent()->textContent;
|
||||
} else {
|
||||
echo 'Looks like we couldn\'t find the content. :(';
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user