View Single Post
Old 11-18-2007, 09:53 PM   #1 (permalink)
joby1
The Visitor
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
joby1 is on a distinguished road
Angry alternative to simplexml command in php4, HELP!!!

just found out my server doesn't have php5 and doesn't plan to for months.

am trying to make a geocoding parsing script (i am very newbie to all this)

there is a great php geocde script here - http://www.developer.com/db/article.php/3621981
but uses simplexml command (line 19) that is not used by php4

found this as a possible alternative for simplexml command-
http://www.shop24-7.info/32-0-simple...tive-php4.html

but being a newbie am clueless how to do it, but i tried to no avail....

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<?php

    
class sxml
{
    var 
$parser;
    var 
$error_code;
    var 
$error_string;
    var 
$current_line;
    var 
$current_column;
    var 
$data = array();
    var 
$datas = array();
    function 
parse($data)
    {
        
$this->parser xml_parser_create('UTF-8');
        
xml_set_object($this->parser$this);
        
xml_parser_set_option($this->parserXML_OPTION_SKIP_WHITE1);
        
xml_set_element_handler($this->parser'tag_open''tag_close');
        
xml_set_character_data_handler($this->parser'cdata');
        if (!
xml_parse($this->parser$data))
        {
            
$this->data = array();
            
$this->error_code xml_get_error_code($this->parser);
            
$this->error_string xml_error_string($this->error_code);
            
$this->current_line xml_get_current_line_number($this->parser);
            
$this->current_column xml_get_current_column_number($this->parser);
        }
        else
        {
            
$this->data $this->data['child'];
        }
        
xml_parser_free($this->parser);
    }

    function 
tag_open($parser$tag$attribs)
    {
        
$this->datas[] =& $this->data;
        
$this->data =& $this->data['child'][$tag][];
    }

    function 
cdata($parser$cdata)
    {
        @
$this->data['data'] .= $cdata;
    }

    function 
tag_close($parser$tag)
    {
        
$this->data =& $this->datas[count($this->datas)-1];
        
array_pop($this->datas);
    }
}

   
// Your Google Maps API key
   
$key "***have removed my google api key but it was in here!!!***";

   
// Desired address
   
$address "http://maps.google.com/maps/geo?q=411+Woody+Hayes+Drive,+Columbus,+OH&output=xml&key=$key";

   
//// Retrieve the URL contents
//   $page = file_get_contents($address);
//
//   // Parse the returned XML file
//   $xml = new SimpleXMLElement($page);
    
    //Demo: Einsatz von sxml

        
$url=$address;

        
$xml_parser = new sxml;
        
$src=implode (''file ($url));
        
$xml_parser->parse($src);
        
$xml=$xml_parser->data;

       
// print_r($xml);
        
   /// Parse the coordinate string
    
list($longitude$latitude$altitude) = explode(","
     
$xml->Response->Placemark->Point->coordinates);

    
// Output the coordinates
    
echo "Longitude: $longitude, Latitude: $latitude";
    
    
    
    

?>

<body>
</body>
</html>
Anyone able to spot the mistake???? just want it to echo the results, will then be using the extended script on page 2 of the first link to mysql it....

Please help.

thanks in advance
joby1 is offline  
Reply With Quote