kylewm/brevity 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

kylewm/brevity

Composer 安装命令:

composer require kylewm/brevity

包简介

A small utility to count characters and shorten posts to tweet-length.

README 文档

README

Build Status

A small utility to count characters, autolink, and shorten posts to an acceptable tweet-length summary.

This is a port of the Python module of the same name. Please refer to https://github.com/kylewm/brevity for documentation.

Note that this module depends on the mb_ string methods to be available. I get the best results by setting

mb_internal_encoding('UTF-8');

somewhere in my project.

Installation

If you're using Composer, you can simply composer require kylewm/brevity.

Otherwise, TODO

Usage

tweetLength($text)

Find out how many characters a message will use on Twitter with tweetLength():

$brevity = new \Kylewm\Brevity\Brevity();
$length = $brevity->tweetLength('Published my first npm www.npmjs.com/package/brevity and composer packagist.org/packages/kylewm/brevity packages today!');
echo $length;  // 99

This text is 119 characters but, due to t.co wrapping, will only use 99 characters.

autolink($text)

Convert URLs in plaintext to HTML links.

$brevity = new \Kylewm\Brevity\Brevity();
$html = $brevity->autolink("I'm a big fan of https://en.wikipedia.org/wiki/Firefly_(TV_series) (and its creator https://en.wikipedia.org/wiki/Joss_Whedon)");
echo $html;

Note that brevity handles parentheses and other punctuation as you'd expect.

shorten($text)

The shorten($text) function takes a message of any length and shortens it to a Tweet-length of 280 characters, adding an ellipsis at the end of it is truncated. It will not truncate a word or URL in the middle. Shorten takes a few optional parameters that change the way the tweet is formed. Any of these parameters can be false.

  • $permalink - included after the ellipsis if and only if the text is shortened. Must be a URL or false.
  • $shortpermalink - included in parentheses at the end of tweets that are not shortened. Must be a URL or false.
  • $shortpermacitation - included in parentheses at the end of tweets that are not shortened. Must not be a URL, e.g. ttk.me t4fT2
  • $formatAsTitle - take the text as a title of a longer article. Always formats as "Title: $permalink" or "Title… $permalink" if shortened.
$brevity = new \Kylewm\Brevity\Brevity();
$permalink = "https://kylewm.com/2016/01/brevity-shortens-notes";
$longnote = "Brevity (github.com/kylewm/brevity-php) shortens notes that are too long to fit in a single tweet. It can also count characters to help you make sure your note won't need to be shortened!";
$tweet = $brevity->shorten($longnote, $permalink);
echo $tweet;

Changes

  • 0.2.10 - 2017-11-25: Account for 280 character limit and multi-byte character weights. Also backports some fixes from the python library.
  • 0.2.8 - 2016-04-19: Support article+media format
  • 0.2.5 - 2016-01-29: Changed namespace from Kylewm to Kylewm\Brevity for better PSR-0 compatibility.

kylewm/brevity 适用场景与选型建议

kylewm/brevity 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 298.65k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2016 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 298.65k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 26
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: CC0
  • 更新时间: 2016-01-29