承接 realodix/readtime 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

realodix/readtime

Composer 安装命令:

composer require realodix/readtime

包简介

Medium's like reading time estimation.

README 文档

README

PHPVersion Build Status GitHub license

📚 Medium's like reading time estimation, based on Medium's read time formula.

Sites like Medium.com have popularized the concept of giving users an estimate for the amount of time it will take them to read the content. With this convenience in mind, ReadTime gives PHP developers the same tool for their readable content. It's a simple feature that will give a nice touch to your PHP application.

Features

  • Calculates read time of images in decreasing progression (Example - 12 seconds for the first image, 11 for the second, until images counted at 3 seconds).
  • Calculates read time of the Chinese / Japanese / Korean characters separately.
  • Removes unwanted html tags to calculate read time more efficiently.

Reference

Installation

You can install the package via composer:

composer require realodix/readtime

Quick start

Here is an example of the most basic usage:

<?php

use Realodix\ReadTime\ReadTime;

$readTime = new ReadTime('foo bar');

echo $readTime->get();
// less than a minute

You may also pass several arguments to the constructor if you wish to change settings on the fly:

/**
 * @param string|array $content   The content to analyze
 * @param int          $wpm       Speed of reading the text in Words per Minute
 * @param int          $imageTime Speed of reading the image in seconds
 * @param int          $cpm       Speed of reading the Chinese / Korean / Japanese
 *                                characters in Characters per Minute
 */

$readTime = new ReadTime($content, $wpm = 265, $imageTime = 12, $cpm = 500);

echo $readTime->get();

The ReadTime class is able to accept a string of content or a array (flat or multidimensional) of multiple pieces of content. This may come in handy if you are attempting to display the total read time of body content along with sidebar content.

For example:

$readTime = new ReadTime([$content, $moreContent, $evenMoreContent]);

echo $readTime->get();

Named arguments are not covered by Realodix Readtime backwards compatibility guidelines. We may choose to rename function arguments when necessary in order to improve codebase. Therefore, using named arguments when calling methods should be done cautiously and with the understanding that the parameter names may change in the future.

Methods

get()

Retrieve the read time.

setTranslation(array $translations)

Manually set the translation text for the class to use. If no key is passed it will default to the English counterpart. A complete translation array will contain the following:

[
    'less_than' => 'less than a minute',
    'one_min'   => '1 min read',
    'more_than' => 'min read',
];
toArray()

Get the contents and settings of the class as an array.

toJson()

Get the contents and settings of the class as a JSON string.

[
    'duration'        => '6 min read',
    'actual_duration' => 5.55,
    'total_words'     => 1325,
    'total_words_cjk' => 0,
    'total_images'    => 3,
    'word_time'       => 5.660,
    'word_time_cjk'   => 0,
    'image_time'      => 0.55,
];
Variable Description
duration Humanized actualDuration for the input
actual_duration Actual duration of the input (in minutes)
total_words Number of words in the input
total_words_cjk Chinese / Japanese / Korean language characters count
total_images Number of images in input
word_time Read time of the words in the input (in minutes)
word_time_cjk Read time of the Chinese / Japanese / Korean in the input (in minutes)
image_time Read time of the images in the input (in minutes)

Contributing

Thank you for your interest in ReadTime. Please check out our contributing guide.

License

This package is licensed using the MIT License.

realodix/readtime 适用场景与选型建议

realodix/readtime 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.2k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2021 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 realodix/readtime 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 realodix/readtime 我们能提供哪些服务?
定制开发 / 二次开发

基于 realodix/readtime 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-26