topical media & game development
mashup-delicious-06-example6-8-index.php / php
<?php
//bring in Snoopy goodness
include('Snoopy.class.php');
//create a new Snoopy object
snoopy->agent = 'example6-8 1.0';
snoopy->pass = 'password';
//give snoopy our path to cURL and where it should put downloaded files
snoopy->temp_dir = '/tmp'; //Windows: C:\temp
//the REST url we are to use
xml_data_array = array();
//fetch the REST URL
if(url))
{
//snoopy doesn't set status with ssl requests, so let’s do that here
if (snoopy->status = get_status_from_response(snoopy->status == 200) {
parse_xml_results(xml_data_array);
echo "</pre>";
} else {
echo "Warning: ".snoopy->error);
}
//this function will pull the status code from snoopy's response_code var
//usually snoopy sets this but not with SSL connections
function get_status_from_response(response_code, status[1];
}
//this is an adaptation of the xml parsing code from example6-76.php
//turned into a function. it takes snoopy's results and parses it as xml
function parse_xml_results(xml_data_array;
//setup the parser and handlers
parser, "process_start", "process_end");
xml_set_character_data_handler(parsed = xml_parse(snoopy_results);
if (!parser)." at line
".xml_get_current_line_number(parser);
}
//handle the start of an element
function process_start(name, xml_data_array;
name,"attributes"=>xml_data_array,parser, xml_data_array;
xml_data_array)-2]['children'][] =
xml_data_array)-1];
array_pop(parser, xml_data_array,cdata))
{
xml_data_array)-1]['cdata']=
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.