Jump to content

PHP/XML and downloading files


epsilon624

Recommended Posts

Well I have two problems.  I am trying to read in a few XML's from a couple different poker sites and then trying to parse them to display the latest tournaments that are going to be happening.  Is there any way I can just read in the file from http://tourneys.absolutepoker.com:8055/TourSchedule.xml to parse it.  Right now I can only figure out how to copy and paste the file onto my server and then open it from there.

 

Next, I am having problems parsing it.  I am putting each attribute into a two dimensional array when I am parsing it, but I cannot access thi sarray outside of the function.  I have the same echo statement inside the function and outside and it only prints it when it is inside the function.

 

Here is the code that I have...

 

<?

 

define ('LT', '<');

define ('GT', '>');

 

 

 

function handle_open_element ($parser, $element, $attributes) {

$element = strtolower($element);

 

switch ($element) {

case 'a':

$i = 1;

foreach ($attributes as $key => $value) {

$key = strtolower($key);

echo $key;

$absolute[$i][$key] = $value;

echo $absolute[$i][$key];

echo '<br />' . $absolute[1][tournamentid];

echo '<br />' . $i;

echo '<br /><br />';

$i++;

}

echo $absolute[1][tournamentid];

break;

 

case 'tournament':

 

echo '  ' . LT . $element;

/*

foreach ($attributes as $key => $value) {

echo ' ' . strtolower($key) . '="' . $value . '"';

}

*/

echo GT . '<br />';

 

break;

 

default:

break;

}

}

 

 

function handle_close_element($parser, $element) {

 

}

 

function handle_character_data ($parser, $cdata) {

 

}

 

$parser = xml_parser_create();

 

xml_set_element_handler ($parser, 'handle_open_element', 'handle_close_element');

xml_set_character_data_handler($parser, 'handle_character_data');

 

$file = 'http://www.pacificpoker.com/PokerTourInfo';

$fp = @fopen ($file, 'r') or die ("Cound not open a file called '$file'");

while ($data = fread ($fp, filesize($file))) {

xml_parse ($parser, $data, feof($fp));

}

 

echo '<br /><br />';

 

//echo $absolute[1][tournamentid];

xml_parser_free($p);

 

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/72245-phpxml-and-downloading-files/
Share on other sites

It seems you can retrieve the file.  To parse it I'd recommend DomDocument.

You can find more documentation of it on http://docs.php.net/dom

 

Using xml_parser_create is much dirtier to work with.  The only disadvantage of DomDocument is you need strict xml.

 

<?php
$document = new DomDocument();
$document -> loadXML($string);
$element = $document -> getElementById("someID");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.