Hi ,
I am new to PHP and I am trying to retireve data from an array with a value of.Firstly I am retrieving values inside the text file that are zipped together.
The values in each file is line separated and comma separated so again I am splitting the data and the retrieving into an array. But the first value of the file is only true or false which gets attached to the first element of the final array.
I just want to get rid of the value true or false and then store the comma seperated values of each line as an attribute of an object which I am not sure how to do.
Below is the sample code:
$zip = zip_open($file_name);
$file_na =array(100000);
$names = array(200);
$n=0;
//block to read files out of a zip file
if (is_resource($zip)) {
while ($zip_entry = zip_read($zip)) {
//echo "<br/>";
zip_entry_name($zip_entry) ;
$names[$n] = zip_entry_name($zip_entry) ;
zip_entry_filesize($zip_entry) ;
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
$file_na[$n]=$buf;
$n++;
zip_entry_close($zip_entry);
}
}
zip_close($zip);
}
//end of block
$lines;
$fields;
$field_values= array(10000);
$cnt=0;
//function to read individual value into an Object
myExplode($file_na);
function myExplode($file_na) {
if (is_array($file_na)) {
foreach ($file_na as $file)
{
$lines = explode ("\n",$file);
// echo $lines[0];
$tempMOs = array();
foreach($lines as $line)
{
$fields = explode (",",$line);
echo "<br/>";
echo $fields[0];
//the first value of this $field[0] will give data like "false 5" whereas just 5 is //needed. Not sure how should I parse this string??
//Also how to store each value as an attribute ( property/individual variable) of an object?
$cnt++;
}
}
}
}
I would really appreciate prompt response. I have attached sample zip file for reference
Thanks!