You are here:  » Basic File Analysis


Basic File Analysis

This example shows a very simple file analysis script that can be used to determine what format string to use for a given source file and what field names are contained within the associative array passed to your record handler function for each record. Just like the demo script on this website it uses PHP's foreach construct to loop through each field in $record.

Assuming that autodetection is successful this demo just displays the contents of the first record in the source file. Click here to view the live output from this script. Remember that you could change $filename to be anything you like, such as the path to a local file rather than an Internet URL (an RSS feed in this example).

<?php
  
require("MagicParser.php");
  
  
header("Content-Type: text/plain");
  
  function 
myRecordHandler($record)
  {
    
print_r($record);
    
    return 
TRUE;
  }

  
$url "http://feeds.bbci.co.uk/news/rss.xml?edition=uk";
  
  print 
"URL: ".$url."\n\n";
  
  
$formatString MagicParser_getFormat($url);
  
  print 
"Format String: ".$formatString."\n\n";
  
  
MagicParser_parse($url,"myRecordHandler",$formatString);
?>