Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Help taking data off page (Eg. Preg_Match() )


Flaming_figures's Avatar
Member
0 0

Well, I've been trying to right a script for this clan I'm working for (gaming clan) and they play Americas Army. What I am trying to do, is go onto aaotracker.com take the Hours of a user and convert it into a variable. Now, I've been around PHP a long time, but I still have issues with preg match. Thus, I have tried to find ways around it.

Now, I want some help actually doing this… I don't care how it is done, as long as I end up with a number of their hours after $hours = ______

I have to use this number in some later scripts, which are really simple once I pull the hours. If you want to try out some preg_match/preg_match_all, here is the section of code I am trying to use.

    <td><font face="Verdana,Arial" size="2"><b>Total time played:</b></font></td>
    <td><font face="Verdana,Arial" size="2">2378.2 hours (1.5 hrs. per day)</font></td>
   </tr>

And of course, I would want a variable holding 2378.2 in it.

I did manage to find an XML file for a the clan wide. I have tried switches, but can't find a way to declare it a variable in the switch (I'll post it later) The XML file is here -> http://aaotracker.com/livefeed/xml_clanprofile.php?clanid=48882

And if it goes through XML, I would need Name, Tracker, Hours AND Honor set as variables.

This is the code I was trying to work with with the XML (my free little server doesn't let me use other URL's in fopen so I had to save a copy, but I should read the aaotracker xml file)


$parser=xml_parser_create();


function start($parser,$element_name,$element_attrs)
  {
  switch($element_name)
    {
    case "PLAYERID":
    echo "Player ID: ";
    break; 
    case "PLAYERNAME":
    echo "Name: ";
    break; 
    case "PLAYERTIME":
    echo "Time: ";
    break; 
    case "PLAYERHONOR":
    echo "Honor: ";
	break;
	default:
	echo "<!--";
    }
  }


function stop($parser,$element_name)
  {
  echo "<br />";
  }

function char($parser,$data)
  {
  echo $data;
  }


xml_set_element_handler($parser,"start","stop");


xml_set_character_data_handler($parser,"char");


$fp=fopen("test.xml","r");

while ($data=fread($fp,4096))
  {
  xml_parse($parser,$data,feof($fp)) or 
  die (sprintf("XML Error: %s at line %d", 
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
  }

xml_parser_free($parser);

Please Help, and tyia… This script has been driving me crazy and I think I officially give up on preg_match 0_o


spyware's Avatar
Banned
0 0

Did you read any RegEx tutorials? If not; go read one. If you still can't figure out how to do this, come back here and post what you've tried/where you're stuck.

Oh, and you know you have to use cURL to grab what you need right? You'll probably want to do this:

cURL page X, grab page source. Use RegEx to find some numbers in the source of page X. Store found numbers in variables. Do something with the found data.