ahenam/estimated-reading-time

计算任何给定网页的阅读时间

0.1.0 2018-02-14 21:10 UTC

This package is auto-updated.

Last update: 2024-09-18 17:27:37 UTC


README

计算任何给定网页的预估阅读时间。

安装

您可以通过composer安装此包

composer require aheenam/estimated-reading-time

使用方法

以下命令返回预估的分钟数,表示阅读给定文本所需的时间。

<?php

// text with 400 words
$text = \Faker\Factory::create()->words(400, true);

// returns 2
(new EstimatedReadingTime)
    ->setText($text)
    ->calculateTime();

在大多数网页中,您没有纯文本,而是HTML片段,但这并不重要。当您使用setText()时,内部会移除这些标签。

设置每分钟默认单词数

默认情况下,假设一个人每分钟可以阅读200个单词,但您可以通过设置属性$wordsPerMinute轻松更改此配置。

<?php

// text with 400 words
$text = \Faker\Factory::create()->words(400, true);

// returns 1
(new EstimatedReadingTime)
    ->setWordsPerMinute(400)
    ->setText($text)
    ->calculateTime();

获取确切时间

另一个默认配置是,此包返回分钟数的四舍五入值。但是,您也可以获取一个确切值。

<?php

$text = \Faker\Factory::create()->words(650, true);

// returns 3.25
(new EstimatedReadingTime)
    ->exactTime(true)
    ->setText($text)
    ->calculateTime();

// returns 3
(new EstimatedReadingTime)
    ->setText($text)
    ->calculateTime();

更新日志

请查看更新日志

测试

要运行测试,请使用

$ composer test

贡献

安全

如果您发现任何与安全相关的问题,请通过电子邮件your@mail.tld或使用GitHub的问题跟踪器。

关于

Aheenam是德国NRW的一家小型公司,专门创建定制数字解决方案。访问我们的网站了解更多关于我们的信息。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件