Hello, Regex is somthing iv never been good with and never really understood on the php help pages. So im having a problem parsing some data thats within a xml page.
Heres a xml output of one of the pages.
<?xml version="1.0" ?>
- <tsqp version="1.0">
<serverinfo uptime="25689" ip="82.23.23.23" servername="Vailera" port="8071" location="Netherlands" url="" server="funstuffS" version="0.9.4d" />
<owner name="AnieGo" email="" />
<players online="35" max="250" peak="63" waiting="0" />
<monsters total="2513" />
<map name="" author="" width="" height="" />
<motd>Welcome to our Server -I have make a new website for u want to look (goto) * www.google.com HAVE FUN!.</motd>
</tsqp>
and heres what im using to parse info from it.
<?
//server packet that needs to be sent to get info
$info = chr(6).chr(0).chr(255).chr(255).'info';
//making socket connection to an ip and port 7171
$sock = @fsockopen('82.1.1.1', 7171, $errno, $errstr, 1);
if ($sock)
{
//writes the info gotten by sending the server packet.
fwrite($sock, $info);
$data='';
while (!feof($sock))
{
$data .= fgets($sock, 1024);
}
fclose($sock);
//players online and max (ex. Players online: 24 / 100) Works
preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches);
print 'Status: Online';
print '<br>Players online: '.$matches[1].' / '.$matches[2];
//Owner Name and e-mail (ex. Owner Name: jasper E-mail: jaja@jaja.com)
preg_match('/owner name="(\D+)" email="(\D+)"/', $data, $matches);
print '<br>Owner Name: '.$matches[1];
//Monster total (ex. Monsters: 23456)Works
preg_match('/monsters total="(\d+)"/', $data, $matches);
print '<br>Monsters: '.$matches[1];
//Distro info (ex. Fun_CVS_5.0.1)
preg_match('/server="((?>\D+)|\d+)*[!?])" version="((?>\D+)|\d+)*[!?])"/', $data, $matches);
print '<br>Distro: '.$matches[1].' '.$matches[2];
//Uptime (Uptime: 23h 12m) Works
preg_match('/uptime="(\d+)"/', $data, $matches);
$h = floor($matches[1] / 3600);
$m = floor(($matches[1] - $h*3600) / 60);
print '<br>Uptime: '.$h.'h '.$m.'m';
}
else
{
print 'Status: Offline';
}
?>
So as you can see I got the numbers down fine (IE. (\d+)) but when it comes to getting chars or a mix of chars, digits and _ symboles Im lost. Looking at what I did I made a mess with crap that dosnt work like ((?>\D+)|\d+)*[!?]) So I need some help.
Can someone fill me in on how I would get the char and _ info using regex? Much thanks in advanced. Oh and also how would I get the info between the <motd> tags?
PS. I commented most of it just in case someone wants to know what the script is doing.