Skip to main content

HOW TO DISPLAY TWITTER FOLLOWERS AS TEXT

In a previous post I showed you to display your Feedburner Subscriber count as text, now here is the code to display your twitter followers as text.
STEP 1

Create a new file in your chosen code editor and copy and paste the following code into the file:

<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() - 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=handyHTML');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?>

Where on line 5 it says “handyHTML” change that to your Twitter User. Once that is done save the file as twitter-count.php, save the file into the root of your websites directory.
STEP 2

Now copy and paste the following code where you want the count to display, this calls the twitter-count.php file we created in Step 1 and outputs the total followers of the specified Twitter account.

<?php include("twitter.php"); ?>

STEP 3

Finally you can style your Twitter count, here is an example:

HTML

<p><span class="twitter-count"><?php include("twitter.php"); ?></span> Followers</p>

CSS

p {
color:#fff;
}

span.twitter-count {
font-size: 22px;
padding-left: 5px;
color: #1e7c9a;
}

…and voila! Come across any problems, comment and one of us will assist you.

Comments

Popular posts from this blog

Base64 Encode and Decode String in PHP

function base64url_encode($plainText) { $base64 = base64_encode($plainText); $base64url = strtr($base64, '+/=', '-_,'); return $base64url;  } function base64url_decode($plainText) { $base64url = strtr($plainText, '-_,', '+/='); $base64 = base64_decode($base64url); return $base64; }

Send Mail using mail function in PHP

$to = "admin@user.vn"; $subject = "User.vn"; $body = "Body of your message here you can use HTML too. e.g. <br> <b> Bold </b>"; $headers = "From: Peter"; $headers .= "Reply-To:  info@yoursite.com "; $headers .= "Return-Path: mailto:info@yoursite.com"; $headers .= "X-Mailer:PHP5"; $headers .= 'MIME-Version: 1.0"; $headers .= 'Content-type: text/html; charset=iso-8859-1"; mail($to,$subject,$body,$headers);