Display Number of Twitter Followers With PHP

There are various ways to display or find out the number of Twitter followers, using Javascript (Jquery) or PHP.

The usefulness of displaying the number of followers also varies, apart from personal statistics, displaying the number of followers is also to make others believe that the website is serious, so it is not uncommon for many people to use the services of a certain person/company to increase the number of followers (we do not will discuss that here).

Previously, tutorial-webdesign.com also discussed how to display the Twitter timeline on a website page, this trick can be combined if needed.

twitter computer
Image credit: Lakeshorebranding.com

Okay, straight to the topic, here we will use PHP to display the number of followers. Enough with just 4 lines of PHP code.

PHP
Create a file with the name twitter_followers_count.php , and fill it as follows

$twitter_id = “tut_web”;
$url = “http://twitter.com/users/show/$twitter_id”;
$response = file_get_contents ( $url );
if(empty($response)){
$count = 0;
}else{
$t_profile = new SimpleXMLElement ( $response );
$count = $t_profile->followers_count;
}
To display it on the web page, simply print it as usual.