Back

实时显示Gtalk状态

|

实例请看侧栏右上角。Google其实已经给出了一段代码,不过有个iframe标签实在很不爽。
打开[这里](http://www.google.com/talk/service/badge/New),获取Google给的代码,例如:[cc lang="html"][/cc]
截取这段代码中的url部分,即http到&之间的部分。

然后写一段php:[cc lang="php"]php
$url = '截取的url';
$chat\_badge = file\_get\_contents($url);
$status = array();
if (preg\_match('|img id=\"b\" src=\"/talk/service/resources/([\w]\*)|',
$chat\_badge, $status))
{
if ($status[1]=='offline')
{
echo '[email protected] -- src="offline.gif"/ 离线';
}
elseif ($status[1]=='busy')
{
echo '[email protected] -- ![](https://r2.livy.fun/2025/12/21/6402d0c0a9d93f4341f5f386180509fd.jpg) 忙碌';
}
elseif ($status[1]=='idle')
{
echo '[email protected] -- ![](https://r2.livy.fun/2025/12/21/6402d0c0a9d93f4341f5f386180509fd.jpg) 离开';
}
elseif ($status[1]=='online')
{
echo '[email protected] -- ![](https://r2.livy.fun/2025/12/21/6402d0c0a9d93f4341f5f386180509fd.jpg) 在线';
}
else
{
echo 'unable to get gtalk status!';
}
}
?>[/cc]
还可以用浏览器打开截取获得的那段url,查看一下源代码,还有多余的信息可以获得,例如自定义状态。

No comments yet

Leave a comment

About me

I live in Tasmania, an island a little far from the rest of the world and very close to the sea.
Father of two little girls, have two puppies.

Work

Work in IT industry, AI is my working partner.