Aravinthan
New Member
- Messages
- 68
- Reaction score
- 0
- Points
- 0
Hi, I used this code before but for some reason when I changed the elemts of it, it stopped working. So here is the part that goes before html tag:
And this is the code that outputs the results:
But for some reason the rank array doesnt show, or shows empty, the rate and active array shows their data.....
How come?
Thanks for your help...
Code:
<?php
$xml_rank_key = "*RATINGS*CLANRATING*RANK";
$xml_rate_key = "*RATINGS*CLANRATING*RATE";
$xml_active_key = "*RATINGS*CLANRATING*ACTIVE";
$story_array = array();
$counter = 0;
class xml_story{
var $rank, $rate, $active;
}
function startTag($parser, $data){
global $current_tag;
$current_tag .= "*$data";
}
function endTag($parser, $data){
global $current_tag;
$tag_key = strrpos($current_tag, '*');
$current_tag = substr($current_tag, 0, $tag_key);
}
function contents($parser, $data){
global $current_tag, $xml_rank_key, $xml_rate_key, $xml_active_key, $counter, $story_array;
switch($current_tag){
case $xml_rank_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->rank = $data;
break;
case $xml_rate_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->rate = $data;
break;
case $xml_active_key:
$story_array[$counter]->active = $data;
$counter++;
break;
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen("[URL]http://www.elorating.com/ranking-services/ratingquery?name=wrwr&mode=SP&laddertype=51&game=3[/URL]", "r") or die("Could not open file");
$data = fread($fp, 4096) or die("Could not read file");
if(!xml_parse($xml_parser, $data))
{
die("Error on line " . xml_get_error_code($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
Code:
<table>
<?php
for($x=0;$x<count($story_array);$x++){
echo "<tr><td>Rank: </td>" ;
echo "<td>" . $story_array[$x]->rank . "</td></tr>";
echo "<tr><td>Rate: </td>" ;
echo "<td>" . round($story_array[$x]->rate, 4) . "</td></tr>";
echo "<tr><td>Active: </td>" ;
echo "<td>" . $story_array[$x]->active . "</td></tr>";
}
?>
</table>
How come?
Thanks for your help...