PHPackages                             kylewm/brevity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kylewm/brevity

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kylewm/brevity
==============

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

0.2.10(8y ago)12293.5k—5.9%4CC0PHP

Since Jan 29Pushed 8y ago2 watchersCompare

[ Source](https://github.com/kylewm/brevity-php)[ Packagist](https://packagist.org/packages/kylewm/brevity)[ RSS](/packages/kylewm-brevity/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (8)Used By (4)

brevity-php
===========

[](#brevity-php)

[![Build Status](https://camo.githubusercontent.com/340e46236e27a8846ff3d58845ff8c4998e20def4ddcb33530db0a2cd91f07bd/68747470733a2f2f7472617669732d63692e6f72672f6b796c65776d2f627265766974792d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kylewm/brevity-php)

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  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
------------

[](#installation)

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

Otherwise, TODO

Usage
-----

[](#usage)

### tweetLength($text)

[](#tweetlengthtext)

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)

[](#autolinktext)

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)

[](#shortentext)

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
-------

[](#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.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~111 days

Recently: every ~165 days

Total

7

Last Release

3118d ago

Major Versions

0.2.9 → 280.x-dev2017-11-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/f57002b1ff46f13dc5dc386fef134f2483135db3747af1c180c6c5ac7bcbe1fe?d=identicon)[kylewm](/maintainers/kylewm)

---

Top Contributors

[![karadaisy](https://avatars.githubusercontent.com/u/950127?v=4)](https://github.com/karadaisy "karadaisy (23 commits)")[![gpluess](https://avatars.githubusercontent.com/u/598360?v=4)](https://github.com/gpluess "gpluess (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kylewm-brevity/health.svg)

```
[![Health](https://phpackages.com/badges/kylewm-brevity/health.svg)](https://phpackages.com/packages/kylewm-brevity)
```

###  Alternatives

[sorich87/bootstrap-tour

Show people how to use your web site

4.4k301.4k](/packages/sorich87-bootstrap-tour)[pmill/php-scheduler

Simple PHP task scheduler

1834.1k](/packages/pmill-php-scheduler)[hydreflab/jedi-faker

Faker extension for Star Wars junkie

1430.1k1](/packages/hydreflab-jedi-faker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
