PHP Class Twitter_Extractor, twitter-text-php

Parses tweets and extracts URLs, usernames, username/list pairs and hashtags. Originally written by {@link http://github.com/mikenz Mike Cochrane}, this is based on code by {@link http://github.com/mzsanford Matt Sanford} and heavily modified by {@link http://github.com/ngnpope Nick Pope}.
Author: Mike Cochrane ([email protected])
Author: Nick Pope ([email protected])
Inheritance: extends Twitter_Regex
Datei anzeigen Open project: ngnpope/twitter-text-php Class Usage Examples

Public Methods

Method Description
__construct ( string $tweet ) Reads in a tweet to be parsed and extracts elements from it.
create ( string $tweet ) : Twitter_Extractor Provides fluent method chaining.
extract ( ) : array Extracts all parts of a tweet and returns an associative array containing the extracted elements.
extractCashtags ( ) : array Extracts all the cashtags from the tweet.
extractCashtagsWithIndices ( ) : array Extracts all the cashtags and the indices they occur at from the tweet.
extractHashtags ( ) : array Extracts all the hashtags from the tweet.
extractHashtagsWithIndices ( ) : array Extracts all the hashtags and the indices they occur at from the tweet.
extractMentionedUsernames ( ) : array Extract all the usernames from the tweet.
extractMentionedUsernamesOrListsWithIndices ( ) : array Extracts all the usernames and the indices they occur at from the tweet.
extractMentionedUsernamesWithIndices ( ) : array Extracts all the usernames and the indices they occur at from the tweet.
extractRepliedUsernames ( ) : array Extract all the usernames replied to from the tweet.
extractURLs ( ) : array Extracts all the URLs from the tweet.
extractURLsWithIndices ( ) : array Extracts all the URLs and the indices they occur at from the tweet.

Protected Methods

Method Description
fixMultiByteIndices ( string &$tweet, array &$matches, array &$results, array $keys, integer $tweak = 1 ) Processes an array of matches and fixes up the offsets to support multibyte strings. This needs to be done due to the state of unicode support in PHP.

Method Details

__construct() public method

Extracts various parts of a tweet including URLs, usernames, hashtags...
public __construct ( string $tweet )
$tweet string The tweet to extract.

create() public static method

Provides fluent method chaining.
See also: __construct()
public static create ( string $tweet ) : Twitter_Extractor
$tweet string The tweet to be converted.
return Twitter_Extractor

extract() public method

Extracts all parts of a tweet and returns an associative array containing the extracted elements.
public extract ( ) : array
return array The elements in the tweet.

extractCashtags() public method

Extracts all the cashtags from the tweet.
public extractCashtags ( ) : array
return array The cashtag elements in the tweet.

extractCashtagsWithIndices() public method

Extracts all the cashtags and the indices they occur at from the tweet.
public extractCashtagsWithIndices ( ) : array
return array The cashtag elements in the tweet.

extractHashtags() public method

Extracts all the hashtags from the tweet.
public extractHashtags ( ) : array
return array The hashtag elements in the tweet.

extractHashtagsWithIndices() public method

Extracts all the hashtags and the indices they occur at from the tweet.
public extractHashtagsWithIndices ( ) : array
return array The hashtag elements in the tweet.

extractMentionedUsernames() public method

A mention is an occurrence of a username anywhere in a tweet.
public extractMentionedUsernames ( ) : array
return array The usernames elements in the tweet.

extractMentionedUsernamesOrListsWithIndices() public method

Extracts all the usernames and the indices they occur at from the tweet.
public extractMentionedUsernamesOrListsWithIndices ( ) : array
return array The username elements in the tweet.

extractMentionedUsernamesWithIndices() public method

Extracts all the usernames and the indices they occur at from the tweet.
public extractMentionedUsernamesWithIndices ( ) : array
return array The username elements in the tweet.

extractRepliedUsernames() public method

A reply is an occurrence of a username at the beginning of a tweet.
public extractRepliedUsernames ( ) : array
return array The usernames replied to in a tweet.

extractURLs() public method

Extracts all the URLs from the tweet.
public extractURLs ( ) : array
return array The URL elements in the tweet.

extractURLsWithIndices() public method

Extracts all the URLs and the indices they occur at from the tweet.
public extractURLsWithIndices ( ) : array
return array The URLs elements in the tweet.

fixMultiByteIndices() protected static method

Processes an array of matches and fixes up the offsets to support multibyte strings. This needs to be done due to the state of unicode support in PHP.
protected static fixMultiByteIndices ( string &$tweet, array &$matches, array &$results, array $keys, integer $tweak = 1 )
$tweet string The tweet being matched.
$matches array The matches from the regular expression match.
$results array The extracted results from the matches.
$keys array The list of array keys to be added.
$tweak integer An amount to adjust the end index by.