You are here:  » Parsing issue (related to the break )


Parsing issue (related to the break )

Submitted by mwong on Tue, 2006-08-15 00:15 in

[2297] => Array
(
[FIELD1] => 18766
[FIELD2] => 23984
[FIELD3] => 34
[FIELD4] => 641093862
[FIELD5] => CHRYSLER MONEY ON THE SALE OF A NEW CAR SHOULD BE PAID
)

[2298] => Array
(
[FIELD1] => ALL THE TIME NOT TO BE TIED TO ANY PROCESS.
)

The FIELD1 's content is actually belongs to FIELD5 of 2297.

the code I use is:
//==============================================================================
set_time_limit(0);
require("MagicParser.php");

$survey_comment= array();
function survey_comment_Handler($record){

global $survey_comment;
$survey_comment[]=$record;
}
MagicParser_parse("SRVYCOMNT.txt","survey_comment_Handler","csv|124|0|34");

echo "";
print_r($survey_comment);
echo "";

echo "survey comment done";
echo sizeof($survey_comment)."";
//==============================================================================

please get the text file in here and take a look,
http://www.mcsofttech.com/dcx/SRVYCOMNT.txt (1.6MB)

thank you much.

Derek

Submitted by support on Tue, 2006-08-15 06:59

Hi Derek,

The best thing to do in this sort of scenario is test for the broken records in myRecordHandler and only add them to the global array when all 5 fields are present and correct.

You can do this with the isset() function, checking for isset($record["FIELD5"]) before adding the record to the global array. Here's the code:

<?php
  set_time_limit
(0);
  require(
"MagicParser.php");
  
$survey_comment= array();
  function 
survey_comment_Handler($record){
    global 
$survey_comment;
    if (isset(
$record["FIELD5"]))
    {
      
$survey_comment[]=$record;
    }
  }
  
MagicParser_parse("SRVYCOMNT.txt","survey_comment_Handler","csv|124|0|34");
  echo 
"";
  
print_r($survey_comment);
  echo 
"";
  echo 
"survey comment done";
  echo 
sizeof($survey_comment)."";
?>

Hope this helps,
Cheers,
David.