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
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");
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.