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; }

NEW HTML5 DOCTYPE

Still using the impossible-to-memorize xHTML Doctype? Then do so no more! It is now much simpler! This… <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> should now be this… <!DOCTYPE html> In fact, did you know that it truthfully isn’t even really necessary for HTML5? However, it’s used for current, and older browsers that require a specified doctype. Browsers that do not understand this doctype will simply render the contained markup in standards mode. So, without worry, feel free to throw caution to the wind, and embrace the new HTML5 doctype.