Skip to content
Twitter text processing library (auto linking and extraction of usernames, lists and hashtags). Based on the Ruby and Java implementations by Matt Sanford
PHP
Find file
Pull request Compare This branch is 54 commits ahead, 4 commits behind mzsanford:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/Twitter Implement Twitter_Validation::getLength().
tests
.gitattributes Updated/fixed .git{attributes,ignore}
.gitignore Updated/fixed .git{attributes,ignore}
.gitmodules Ensure that conformance test submodule is correct.
LICENSE Remove executable permissions.
README Updated documentation.
README.markdown Updated contributors in README.
TODO Updated TODO.
phpunit.xml Updated testing - run phpunit from root of project.

README.markdown

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.

Features

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

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

Examples

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

Conformance

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

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

It has already been added as a git submodule so you should just need to run:

git submodule init
git submodule update

As PHP has no native support for YAML you'll need to checkout spyc from svn into tests/spyc:

svn checkout https://spyc.googlecode.com/svn/trunk/ tests/spyc

There are a couple of options for testing conformance:

  1. Run phpunit in from the root folder of the project.
  2. Run tests/runtests.php from the command line.
  3. Make tests/runtests.php accessible on a web server and view it in your browser.

Thanks & Contributions

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

Something went wrong with that request. Please try again.