PHP Classes
elePHPant
Icontem

PHP Twitter Share Button: Generate HTML for button to share page on Twitter

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-05-10 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 5 This week: 5All time: 9,295 This week: 73Up
Version License PHP version Categories
twitter-sharer 1.0Custom (specified...5HTTP, PHP 5, Social Networking
Description Author

This class can generate HTML for button to share page on Twitter.

It takes as parameters a message text, a Twitter user name, a page URL to share and some tracking parameter values.

The class generates HTML with JavaScript and a link to display the button on a Web page so when the users click on the button it will open a page to share the specified page on Twitter.

  Performance   Level  
Name: Jackson Morais <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: 17
All time rank: 4218348 in Brazil Brazil
Week rank: 79 Up2 in Brazil Brazil Up

Details

Twitter Sharer - Docs

Create quick and easy tweet buttons!

Build Status

Instalation

It's recommended that you use Composer to install Twitter Sharer.

$ composer require jkmorais/twitter-sharer

Twitter Sharer requires PHP 5.3.3 or newer.

Quick examples

Creating a custom tweet button

<?php
  require 'vendor/autoload.php';
  $tweet = new Sharer\Tweet;    

  $button = $tweet->button(
  'Hello Twitter!', // the tweet text
  'MyUsername', // via @MyUsername
  'http://mywebsite.com', // the tweet url
  Array(
    'hashtag1', 'hashtag2', 'hashtag3' // the tweet hashtags
  ),
  'large' // size of tweet button. This is an optional parameter. By default, the size of the button is 'small'
);

print $button;

To create a tweet button without url or without via username, just use [none] as a parameter.

$button = $tweet->button(
  'Hello Twitter!',
  '[none]',
  '[none]',
  Array(
    'hashtag1', 'hashtag2', 'hashtag3'
  )
);

To tweet the current page address, just use [this] as parameter in the URL

$button = $tweet->button(
  'Hello Twitter!',
  'MyUsername',
  '[this]', // will be the current URL
  Array(
    'hashtag1', 'hashtag2', 'hashtag3'
  )
);

Print (or echo) the $button variable to show the tweet button

Where to get help

Found a bug? Got a question? Just not sure how something works? Please create an issue and I'll do my best to help out. Alternatively you can catch me on Twitter

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageSharer (1 file)

  Files folder image Files  /  src  /  Sharer  
File Role Description
  Plain text file Tweet.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageSharer (1 file)
  Accessible without login Plain text file test.php Example Example script

  Files folder image Files  /  tests  /  Sharer  
File Role Description
  Plain text file TweetTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:5
This week:5
All time:9,295
This week:73Up