PHPackages                             nojimage/twitter-text-php - 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. nojimage/twitter-text-php

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

nojimage/twitter-text-php
=========================

A library of PHP classes that provide auto-linking and extraction of usernames, lists, hashtags and URLs from tweets.

v3.4.0(5mo ago)1241.9M—7.1%217Apache-2.0PHPPHP &gt;=7.4CI passing

Since Jul 26Pushed 5mo ago6 watchersCompare

[ Source](https://github.com/nojimage/twitter-text-php)[ Packagist](https://packagist.org/packages/nojimage/twitter-text-php)[ Docs](https://github.com/nojimage/twitter-text-php)[ RSS](/packages/nojimage-twitter-text-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (7)

Twitter Text (PHP Edition)
==========================

[](#twitter-text-php-edition)

A library of PHP classes that provide auto-linking and extraction of usernames, lists, hashtags and URLs from tweets. Originally created from twitter-text-rb and twitter-text-java projects by Matt Sanford and ported to PHP by Mike Cochrane, this library has been improved and made more complete by Nick Pope.

 [ ![Build Status](https://github.com/nojimage/twitter-text-php/actions/workflows/ci.yml/badge.svg) ](https://github.com/nojimage/twitter-text-php/actions/workflows/ci.yml) [ ![Codecov](https://camo.githubusercontent.com/20189aa2a5eee2c9bba9ce6d937adb4b2476861ff6dabdb467712ef4e9de0a35/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6f6a696d6167652f747769747465722d746578742d7068702e7376673f7374796c653d666c61742d737175617265) ](https://codecov.io/gh/nojimage/twitter-text-php) [ ![Latest Stable Version](https://camo.githubusercontent.com/52cae042e5aef6456fd91dd5fe1ba037cc6f9af1ecd2d4404dd70e4840af2c81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f6a696d6167652f747769747465722d746578742d7068702e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/nojimage/twitter-text-php)

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- ext-mbstring
- ext-intl

If the necessary extensions are not installed on the server, please install it additionally or use [symfony/polyfill](https://github.com/symfony/polyfill).

Install
-------

[](#install)

You can install this library into your application using [Composer](https://getcomposer.org/).

```
composer require nojimage/twitter-text-php

```

### Note for Older Server

[](#note-for-older-server)

This library use intl/libICU. Some older server and PHP 7.2+ combinations may have deprecated warnings due to older ICU versions. [refs #32](https://github.com/nojimage/twitter-text-php/issues/32)

If you are using RHEL/CentOS 6, installing PHP using [the remi repository](https://rpms.remirepo.net/) is the best choice. If you use remi, you can use the new ICU.

Features
--------

[](#features)

### Autolink

[](#autolink)

- Add links to all matching Twitter usernames (no account verification).
- Add links to all user lists (of the form @username/list-name).
- Add links to all valid hashtags.
- Add links to all URLs.
- Support for international character sets.

### Extractor

[](#extractor)

- Extract mentioned Twitter usernames (from anywhere in the tweet).
- Extract replied to Twitter usernames (from start of the tweet).
- Extract all user lists (of the form @username/list-name).
- Extract all valid hashtags.
- Extract all URLs.
- Support for international character sets.

### Hit Highlighter

[](#hit-highlighter)

- Highlight text specifed by a range by surrounding with a tag.
- Support for highlighting when tweet has already been autolinked.
- Support for international character sets.

### Validation

[](#validation)

- Validate different twitter text elements.
- Support for international character sets.

### Parser

[](#parser)

- Parses a given tweet text with the weighted character count configuration.

Length validation
-----------------

[](#length-validation)

twitter-text 3.0 updates the config file with `emojiParsingEnabled` config option. When true, twitter-text-php will parse and discount emoji supported by the [Unicode Emoji 11.0](http://www.unicode.org/emoji/charts-11.0) (NOTE: Original [twitter-text](https://github.com/twitter/twitter-text) supported [twemoji library](https://github.com/twitter/twemoji)). The length of these emoji will be the default weight (200 or two characters) even if they contain multiple code points combined by zero-width joiners. This means that emoji with skin tone and gender modifiers no longer count as more characters than those without such modifiers.

twitter-text 2.0 introduced configuration files that define how Tweets are parsed for length. This allows for backwards compatibility and flexibility going forward. Old-style traditional 140-character parsing is defined by the v1.json configuration file, whereas v2.json is updated for "weighted" Tweets where ranges of Unicode code points can have independent weights aside from the default weight. The sum of all code points, each weighted appropriately, should not exceed the max weighted length.

Some old methods from twitter-text-php 1.0 have been marked deprecated, such as the `Twitter\Text\Validator::isValidTweetText()`, `Twitter\Text\Validator::getTweetLength()` method. The new API is based on the following method, `Twitter\Text\Parser::parseTweet()`

```
use Twitter\Text\Parser;
$parser = new Parser();
$result = $parser->parseTweet($text);

```

This method takes a string as input and returns a results object that contains information about the string. `Twitter\Text\ParseResults` object includes:

- `weightedLength`: the overall length of the tweet with code points weighted per the ranges defined in the configuration file.
- `permillage`: indicates the proportion (per thousand) of the weighted length in comparison to the max weighted length. A value &gt; 1000 indicates input text that is longer than the allowable maximum.
- `valid`: indicates if input text length corresponds to a valid result.
- `displayRangeStart, displayRangeEnd`: An array of two unicode code point indices identifying the inclusive start and exclusive end of the displayable content of the Tweet. For more information, see the description of `display_text_range` here: [Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates)
- `validRangeStart, validRangeRnd`: An array of two unicode code point indices identifying the inclusive start and exclusive end of the valid content of the Tweet. For more information on the extended Tweet payload see [Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates)

Examples
--------

[](#examples)

For examples, please see `tests/example.php` which you can view in a browser or run from the command line.

Conformance
-----------

[](#conformance)

You'll need the test data which is in YAML format from the following repository:

```
https://github.com/twitter/twitter-text

```

`twitter/twitter-text` already included in `composer.json`, so you should just need to run:

```
curl -s https://getcomposer.org/installer | php
php composer.phar install

```

There are a couple of options for testing conformance:

- Run `phpunit` in from the root folder of the project.

Thanks &amp; Contributions
--------------------------

[](#thanks--contributions)

The bulk of this library is from the heroic efforts of:

- Matt Sanford (): For the orignal Ruby and Java implementions.
- Mike Cochrane (): For the initial PHP code.
- Nick Pope (): For the bulk of the maintenance work to date.
- Takashi Nojima (): For ongoing maintenance work.

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance70

Regular maintenance activity

Popularity56

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 76.3% 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 ~237 days

Recently: every ~277 days

Total

20

Last Release

168d ago

Major Versions

v1.14.2 → v2.0.02018-01-16

v2.0.3 → v3.0.02018-10-31

PHP version history (3 changes)1.1.0PHP &gt;=5.2.8

v1.14.0PHP &gt;=5.3.3

v3.2.0PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![nojimage](https://avatars.githubusercontent.com/u/100564?v=4)](https://github.com/nojimage "nojimage (287 commits)")[![ngnpope](https://avatars.githubusercontent.com/u/2855582?v=4)](https://github.com/ngnpope "ngnpope (65 commits)")[![F21](https://avatars.githubusercontent.com/u/2263040?v=4)](https://github.com/F21 "F21 (4 commits)")[![jeherve](https://avatars.githubusercontent.com/u/426388?v=4)](https://github.com/jeherve "jeherve (3 commits)")[![mikenz](https://avatars.githubusercontent.com/u/6816?v=4)](https://github.com/mikenz "mikenz (3 commits)")[![jfoulquie-tnw](https://avatars.githubusercontent.com/u/159464174?v=4)](https://github.com/jfoulquie-tnw "jfoulquie-tnw (3 commits)")[![sololance](https://avatars.githubusercontent.com/u/36849576?v=4)](https://github.com/sololance "sololance (3 commits)")[![alirezameskin](https://avatars.githubusercontent.com/u/36147?v=4)](https://github.com/alirezameskin "alirezameskin (1 commits)")[![sunils34](https://avatars.githubusercontent.com/u/692851?v=4)](https://github.com/sunils34 "sunils34 (1 commits)")[![beesofts](https://avatars.githubusercontent.com/u/1955007?v=4)](https://github.com/beesofts "beesofts (1 commits)")[![blkaspars](https://avatars.githubusercontent.com/u/2241332?v=4)](https://github.com/blkaspars "blkaspars (1 commits)")[![gmmarc](https://avatars.githubusercontent.com/u/7556242?v=4)](https://github.com/gmmarc "gmmarc (1 commits)")[![kennethkufluk](https://avatars.githubusercontent.com/u/156496?v=4)](https://github.com/kennethkufluk "kennethkufluk (1 commits)")[![mzsanford](https://avatars.githubusercontent.com/u/33917?v=4)](https://github.com/mzsanford "mzsanford (1 commits)")[![rintaun](https://avatars.githubusercontent.com/u/82698?v=4)](https://github.com/rintaun "rintaun (1 commits)")

---

Tags

autolinkextract-texthashtagphp-librarytwittertextextracttwitterautolink

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nojimage-twitter-text-php/health.svg)

```
[![Health](https://phpackages.com/badges/nojimage-twitter-text-php/health.svg)](https://phpackages.com/packages/nojimage-twitter-text-php)
```

###  Alternatives

[froala/wysiwyg-editor

A beautiful jQuery WYSIWYG HTML rich text editor. High performance and modern design make it easy to use for developers and loved by users.

5.4k306.9k3](/packages/froala-wysiwyg-editor)[ckeditor/ckeditor

JavaScript WYSIWYG web text editor.

5234.2M76](/packages/ckeditor-ckeditor)[tinymce/tinymce

Web based JavaScript HTML WYSIWYG editor control.

1697.5M106](/packages/tinymce-tinymce)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

374468.4k51](/packages/flow-php-etl)[honeystone/laravel-seo

SEO metadata and JSON-LD package for Laravel.

34744.1k](/packages/honeystone-laravel-seo)[iamcal/lib_autolink

Adds anchors to urls in a text

631.3M3](/packages/iamcal-lib-autolink)

PHPackages © 2026

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