You are here:  » Generated PhP code not showing any results.


Generated PhP code not showing any results.

Submitted by mrlate on Mon, 2011-01-31 00:30 in

Hi,

I'm experimenting with NextBus and can't seem to get anything to display. I am using the demo code created from the url.

I'm trying to get the info displayed in an HTML page.

Here is the code:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    
print_r($record);
    
// The following code will print out each field in your sample data:
    
print $record["VEHICLE"];
    print 
$record["VEHICLE-ID"];
    print 
$record["VEHICLE-ROUTETAG"];
    print 
$record["VEHICLE-DIRTAG"];
    print 
$record["VEHICLE-LAT"];
    print 
$record["VEHICLE-LON"];
    print 
$record["VEHICLE-SECSSINCEREPORT"];
    print 
$record["VEHICLE-PREDICTABLE"];
    print 
$record["VEHICLE-HEADING"];
    print 
$record["VEHICLE-SPEEDKMHR"];
  }
  
MagicParser_parse("http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=sf-muni&r=N&t=1144953510433","myRecordHandler","xml|BODY/VEHICLE/");
?>

Sorry if I'm a newbie but I am trying to understand the code. I have checked several other topics in the forum and I can't seem to find what I am doing wrong.

Thank you!!

Submitted by support on Mon, 2011-01-31 09:10

Hi mrlate,

This is almost certainly because URL wrappers are not enabled on your PHP installation. These are required for PHP to be able to fopen() an Internet URL, which is what Magic Parser does internally. More information about URL wrappers can be found here:

http://uk2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

However, it is becoming more and more common for CURL to be installed, which is an alternative method for accessing remote URLs. To try using CURL, in place of the following code in your script:

  MagicParser_parse("http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=sf-muni&r=N&t=1144953510433","myRecordHandler","xml|BODY/VEHICLE/");

...instead, use:

  $url = "http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=sf-muni&r=N&t=1144953510433";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $xml = curl_exec($ch);
  curl_close($ch);
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|BODY/VEHICLE/");

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by mrlate on Wed, 2011-02-02 02:12

Hi David,

Wow, that is what I call support!!

Worked and thank you!!