PHP Classes
elePHPant
Icontem

PHP String Socializer: Replace text with hash tags and social media links

Recommend this page to a friend!
  Info   View files Example   Demos   Screenshots Screenshots   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-07-09 (3 years ago) RSS 2.0 feedStarStarStarStar 64%Total: 162 All time: 8,606 This week: 325Up
Version License PHP version Categories
phpstringsocializer 1.1GNU General Publi...5HTML, PHP 5, Text processing, Social ...
Description Author

This class can replace text with hash tags and social media links.

It takes an given text and an array of hash tag definitions and replaces text that match the tags with # or @ and links to the respective user profiles in social network media sites.

It may just replace the text or convert it to HTML too so it can add the links.

Currently it supports social networks like Facebook, Twitter, Instagram, Google Plus, Tumblr, and Pinterest.

Innovation Award
PHP Programming Innovation award nominee
July 2016
Number 5


Prize: PhpStorm IDE 1 year individual subscription
Sometimes you need to post a text that has references to social network profiles or hash tags.

This class can take a given text and replace user names or hash tags prefixed with @ or # with a list of known tags to be linked to the respective social network pages.

Manuel Lemos
  Performance   Level  
Name: Luciano Salvino <contact>
Classes: 11 packages by
Country: Argentina Argentina
Age: 46
All time rank: 148518 in Argentina Argentina
Week rank: 294 Up3 in Argentina Argentina Up
Innovation award
Innovation award
Nominee: 9x

 

Details

StringSocializer

StringSocializer is a simple PHP class that converts string into social media rich text. It add hashtags and mentions custimized for each social network

Usage

// Initialize Class
$stringSocializer = new stringSocializer();

// set original String
$originalString = 'El partido estaba igualado sin tantos hasta que el genio de Lionel Messi frotó la lámpara y sacó una jugada mágica de la galera para poner con remate cruzado el 1 a 0. tres minutos después una jugada velóz de Luis Suarez dejó solo a Neymar quien definió suave a la izquierda para decretar el 2 a 0 final.';
$stringSocializer->setOriginalString($originalString);

// Hashtags and Mentions for many social networks
$hashtags = array(
             'facebook' => array(
                    array(
                        'title' => 'LeoMessi',
                        'mention' => 'LeoMessi',
                        'names'   => array('/Lionel Messi/i') 
                    ),
                    array(
                        'title' => 'NeymarJr',
                        'mention' => 'Neymarjr',
                        'names'   => array('/Neymar/i') 
                    ),
                    array(
                        'title' => 'LuisSuarez',
                        'mention' => 'Luis-Suarez-167866666571743',
                        'names'   => array('/Luis Suarez/i') 
                    )
                ),
             'twitter' => array(
                    array(
                        'title' => 'Messi',
                        'hashtag' => 'Messi',
                        'names'  => array('/Lionel Messi/i') 
                    ),
                    array(
                        'title' => 'NeymarJr',
                        'mention' => 'neymarjr',
                        'names'   => array('/Neymar/i') 
                    ),
                    array(
                        'title' => 'LuisSuarez9',
                        'mention' => 'LuisSuarez9',
                        'names'   => array('/Luis Suarez/i') 
                    )
                ),
             'instagram' => array(
                    array(
                        'title' => 'LeoMessi',
                        'mention' => 'leomessi',
                        'names'  => array('/Lionel Messi/i') 
                    ),
                    array(
                        'title' => 'NeymarJr',
                        'mention' => 'neymarjr',
                        'names'   => array('/Neymar/i') 
                    ),
                    array(
                        'title' => 'LuisSuarez9',
                        'mention' => 'LuisSuarez9',
                        'names'   => array('/Luis Suarez/i') 
                    )
                ),
             'googleplus' => array(
                    array(
                        'title' => 'LeoMessi',
                        'hashtag' => 'LeoMessi',
                        'names'   => array('/Lionel Messi/i') 
                    ),
                    array(
                        'title' => 'NeymarJr',
                        'mention' => '110543884226915019329',
                        'names'  => array('/Neymar/i') 
                    ),
                    array(
                        'title' => 'LuisSuarez',
                        'mention' => '117508493298516511885',
                        'names'   => array('/Luis Suarez/i') 
                    )             
                ),
             'tumblr'   => array(),
             'pinterest'   => array(),
             );
$stringSocializer->setHashtags($hashtags);

// You can set the in html or text plain (optional)
$stringSocializer->setHtml(true);

// Socialize string
$stringSocializer->socializeString();

// Get the array result with the string customized for each social network
$arrayResult = $stringSocializer->getStringSocialized();
  fastfor.meExternal page   fastfor.me - TwitterExternal page  
Screenshots  
  • example
  Files folder image Files  
File Role Description
Accessible without login Plain text file composer.json Data Composer
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file README.md Data Readme
Plain text file stringSocializer.php Class Class

 Version Control Unique User Downloads Download Rankings  
 80%
Total:162
This week:0
All time:8,606
This week:325Up
 User Ratings  
 
 All time
Utility:93%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:-
Examples:87%StarStarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:893