2017 © Pedro Peláez
 

library twitter-text-php

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

image

nojimage/twitter-text-php

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

  • Tuesday, July 24, 2018
  • by nojimage
  • Repository
  • 4 Watchers
  • 66 Stars
  • 91,873 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 73 Forks
  • 1 Open issues
  • 12 Versions
  • 8 % Grown

The README.md

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., (*1)

Build Status Codecov Latest Stable Version , (*2)

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., (*3)

Install

You can install this library into your application using Composer., (*4)

composer require nojimage/twitter-text-php

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, (*5)

If you are using RHEL/CentOS 6, installing PHP using the remi repository is the best choice. If you use remi, you can use the new ICU., (*6)

Features

  • 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

  • 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

  • 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

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

Parser

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

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 (NOTE: Original twitter-text supported twemoji library). 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., (*7)

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., (*8)

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(), (*9)

(php) use Twitter\Text\Parser; $parser = new Parser(); $result = $parser->parseTweet($text);, (*10)

This method takes a string as input and returns a results object that contains information about the string. Twitter\Text\ParseResults object includes:, (*11)

  • weightedLength: the overall length of the tweet with code points weighted per the ranges defined in the configuration file., (*12)

  • permillage: indicates the proportion (per thousand) of the weighted length in comparison to the max weighted length. A value > 1000 indicates input text that is longer than the allowable maximum., (*13)

  • valid: indicates if input text length corresponds to a valid result., (*14)

  • 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, (*15)

  • 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, (*16)

Examples

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

Conformance

You'll need the test data which is in YAML format from the following repository:, (*18)

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

twitter/twitter-text already included in composer.json, so you should just need to run:, (*19)

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

There are a couple of options for testing conformance:, (*20)

  • Run phpunit in from the root folder of the project.

Thanks & Contributions

The bulk of this library is from the heroic efforts of:, (*21)

  • Matt Sanford (https://github.com/mzsanford): For the orignal Ruby and Java implementions.
  • Mike Cochrane (https://github.com/mikenz): For the initial PHP code.
  • Nick Pope (https://github.com/ngnpope): For the bulk of the maintenance work to date.
  • Takashi Nojima (https://github.com/nojimage): For ongoing maintenance work.

The Versions

24/07 2018

dev-master

9999999-dev https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-mbstring *
  • ext-intl *

 

The Development Requires

text extract twitter autolink

17/05 2018

dev-develop

dev-develop https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-mbstring *
  • ext-intl *

 

The Development Requires

text extract twitter autolink

17/05 2018

v2.0.3

2.0.3.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-mbstring *
  • ext-intl *

 

The Development Requires

text extract twitter autolink

15/02 2018

v2.0.2

2.0.2.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-mbstring *
  • ext-intl *

 

The Development Requires

text extract twitter autolink

18/01 2018

v2.0.1

2.0.1.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-mbstring *
  • ext-intl *

 

The Development Requires

text extract twitter autolink

16/01 2018

v2.0.0

2.0.0.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-mbstring *
  • ext-intl *

 

The Development Requires

text extract twitter autolink

28/12 2017

dev-feature/twitter-text-2.0

dev-feature/twitter-text-2.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • php-mbstring *
  • php-intl *

 

The Development Requires

text extract twitter autolink

21/09 2017

v1.14.2

1.14.2.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

text extract twitter autolink

21/09 2017

v1.14.1

1.14.1.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

text extract twitter autolink

21/09 2017

v1.14.0

1.14.0.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

text extract twitter autolink

28/02 2014

1.1.1

1.1.1.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.8

 

The Development Requires

text extract twitter autolink

26/07 2013

1.1.0

1.1.0.0 https://github.com/nojimage/twitter-text-php

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

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.8

 

The Development Requires

text extract twitter autolink