// set the username of the person
$user = 'fbelzile' /*'manikowski'*/;
// get the profile page from the xfire server
// you have to have allow-url-fopen enabled
// info: http://uk2.php.net/ref.filesystem#ini.allow-url-fopen
$page = file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=profile&uname=' . $user);
// match the "User is: online/offline"
preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU'
,$page,$match);
// if everything worked,
// $match[1] is now online or offline
echo $user . ' is ' . $match[1];
?>
If you want multiple users, and they will all be in your (or someone else's) friends list, you could grab them all at the same time and sort using pre_match_all. It would be faster than getting them individually because you'd only have to request one page instead of many pages.
This outputs a HTML list of users and status from the page, the person's profile first, and all the people from the friends list:
PHP Code:
<?php
// set the username of the person
$user = 'fbelzile';
// get the profile page from the xfire server
// you have to have allow-url-fopen enabled
// info: http://uk2.php.net/ref.filesystem#ini.allow-url-fopen
if(($page = file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=profile&uname=' . $user)) === false)
{
exit('Could not load file.');
}
// match the "User is: online/offline"
preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU',$page,$match);
// match you friends status's
preg_match_all('#\<li\>\s+\<span class\="status"\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>.+\</span\>.+\<a href\="[^"]+"\>([^\<]+)\</a\>#isU',$page,$matches);
// echo profile owners status
echo "<ul>\n\t<li>" . $user . ' is ' . $match[1] . '</li>';
// loop through and echo friends status's
foreach($matches[2] as $key => $value)
{
// $value is the username and $matches[1][$key] is the status
echo "\n\t<li>" . $value . ' is ' . $matches[1][$key] . '</li>';
}
echo "\n</ul>";
you'd need to setup a loop before calling this script. Not such a flexible example (would be more flexible if you were pulling information from database)
// set the username of the person $user = 'fbelzile';
// get the profile page from the xfire server // you have to have allow-url-fopen enabled // info: http://uk2.php.net/ref.filesystem#ini.allow-url-fopen if(($page = file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=friends&uname=' . $user)) === false) { exit('Could not load file.'); }
// match the "User is: online/offline" preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU',$page,$match);
// match you friends status's preg_match_all('#\<td width\="22%"\>\s+\<a href\="modules\.php\?[^"]+"\>([^\<]+)\</a\>\s+\</td\>\s+\<td width\="13%"\>\s+\<span class\="[^"]+"\>(online|offline)\</span\>#isU',$page,$matches);
// start the HTML list echo "<ul>\n\t";
// check if the profile's owner is online if($match[1] == 'online') { echo '<li>' . $user . '</li>'; }
// loop through the matched friends foreach($matches[1] as $key => $value) { // check if they're online. if($matches[2][$key] == 'online')