Motyar

@motyar

Freelance Web Developer

Static Web Hosting, made easy

Apr 13, 2010

Gtalk status checker with php

Today we are here to create a php script, that will show your gtalk status, ONLINE, OFFLINE, BUSY or AWAY. This code is based on the Google Talk chatback badge. We are fetching the url with help of cURL and then fetching status with Regular expressions.



Ideas

As i told you we are using a google's Google Talk chatback badge with php. You must know your chatback url

Getting your chatback url

Its very simple, i am trying to describe in some steps-
Go to Google Talk chatback badge










Click on the "Edit" link and choose Url only (no frame) Style for your badge.





Now pic your chatback url

Code

Here is the php code that will show your gtalk status -

<?php 
// your url here 
$url "http://www.google.com/talk/service/badge/Show?tk=whatever";
$ch curl_init($url);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
$data curl_exec($ch); 
//parsing HTML 
preg_match('/<div class="r"><img id="b" src="(.*)" alt="" height="9" width="9"><img id="f"/i', 
$data,$match);
$status substr($match[1],24,2);

if($status == 'on'){
    echo "AVAILABLE";
}
elseif($status == 'bu'){
    echo "BUSY";
}
elseif($status=='of'){
    echo "OFFLINE";
}
else{
    echo "AWAY";
}
?>                     



Related articles

Weather forecast php application in 7 lines
Create your own gtalk robot
Php api for your gtalk

Labels: ,




By :