PHP Classes

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

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 26 All time: 11,235 This week: 673Up
Version License PHP version Categories
twitter-sharer 1.0.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.

Picture of Jackson Morais
  Performance   Level  
Name: Jackson Morais <contact>
Classes: 1 package by
Country: Brazil Brazil

Example

<?php
require_once __DIR__ . '/../vendor/autoload.php'; // Autoload files using Composer autoload
use Sharer\Tweet;

$tw = new Tweet();

$btn = $tw->button(
   
"I dowloaded 'twitter-sharer' with composer!",
   
'[none]',
   
'https://github.com/Jkmorais/twitter-sharer',
    Array(
       
'Composer', 'Packagist', 'GitHub', 'OpenSource'
   
)
);

print
$btn;


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 (8)  
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 (8)  /  src  
File Role Description
Files folder imageSharer (1 file)

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

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

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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:26
This week:0
All time:11,235
This week:673Up