You are here:  » Undefined offset


Undefined offset

Submitted by baggagepin on Thu, 2010-09-23 13:15 in

Hi David,

I have been working on a script which for a reason I can't see has started to produce an error.

I removed all the code apart from the "MajicParser part. When I run the script I get the following error:

Notice: Undefined offset: 15 in /var/www/vhosts/mydomain/httpdocs/MagicParser.php on line 2

Can you see why the error is being output. The code I am using is:

<?php
 
error_reporting
(E_ALL);
ini_set("display_errors"1);
require(
"/var/www/vhosts/mydomain/httpdocs/MagicParser.php");      
// READ RECORDS FROM INCOMING CSV DATA FILE
 
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["ArrDep"];
    print 
$record["Airline"];
    print 
$record["FltNo"];
    print 
$record["Time"];
    print 
$record["Est"];
    print 
$record["City1"];
    print 
$record["City2"];
    print 
$record["Stat"];
    print 
$record["Gate"];
    print 
$record["Term"];
    print 
$record["Type"];
    print 
$record["Reg"];
    print 
$record["Run"];
    print 
$record["Stand"];
    print 
$record["Date"];
    print 
$record[""];
  }
$result MagicParser_parse("/var/www/vhosts/flightq.com/httpdocs/xml/HEATHROW.002","myRecordHandler","csv|44|1|0");
?>

The output is:

Notice: Undefined offset: 15 in /var/www/vhosts/flightq.com/httpdocs/MagicParser.php on line 2
Array ( [ArrDep] => I [Airline] => AI [FltNo] => 188 [Time] => 1130 [Est] => 1630 [City1] => YYZ [City2] => [Stat] => 03 [Gate] => [Term] => 3 [Type] => 77W [Reg] => VTALM [Run] => [Stand] => [Date] => 20100923 [] => ) IAI18811301630YYZ03377WVTALM20100923
Notice: Undefined offset: 15 in /var/www/vhosts/flightq.com/httpdocs/MagicParser.php on line 2
Array ( [ArrDep] => I [Airline] => BA [FltNo] => 196 [Time] => 1135 [Est] => 1632 [City1] => IAH [City2] => [Stat] => 03 [Gate] => [Term] => 5 [Type] => 744 [Reg] => GCIVW [Run] => [Stand] => [Date] => 20100923 [] => ) IBA19611351632IAH035744GCIVW20100923

and so on. Many thanks for any help you can provide.

Cheers,

Dereck

Submitted by support on Thu, 2010-09-23 17:49

Hi Derek,

Undefined offset is a warning rather than an error - if you replace

error_reporting(E_ALL);

with:

error_reporting(E_ERROR);

...that should suppress the warning output...

Cheers,
David.