sukohi / shellless

一个PHP包,用于从HTML中提取可读文本。

1.0.0 2017-03-13 09:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:09:50 UTC


README

一个PHP包,用于从HTML中提取可读文本。

安装

执行以下命令。

composer require sukohi/shellless:1.*

用法

use Sukohi\Shellless\Shellless;

$html = file_get_contents('http://example.com/');
$shellless = new Shellless();
$result = $shellless->extract($html);

echo $result->title;        // Page title

echo $result->best_text;    // The longest text

echo $result->full_text;    // Joined text if more than 100 characters length.

print_r($result->all_texts, true);

选项

$shellless->setOptions([
    'join_step' => 5,
    'min_text_length' => 100
]);

算法

  1. 如果它们之间少于5个HTML标签,则合并紧密的文本。
  2. 如果文本长度超过100个字符,则选择文本。

许可证

本软件包根据MIT许可证授权。
版权所有 © 2017 Sukohi Kuhoh