<?php
$data =
"name year serial charge daysout revenue price hours dep maint
name year serial charge daysout revenue price hours dep maint
name year serial charge daysout revenue price hours dep maint
";
?>
and I need to extract the data and put into an array using strtok like below. Where I'm confused is that only the first 8 fields are needed and skip the last 2 fields. I may be close as a for loop will do this task, but I'm not sure how to skip the 2 fields.
How can this be accomplished? Am I close?
Code: Select all
include 'inventory.php';
$equipment['name'] = rtrim(strtok($data, " "));
$equipment['year'] = rtrim(strtok(" "));
$equipment['serial'] = rtrim(strtok(" "));
$equipment['charge'] = rtrim(strtok(" "));
$equipment['daysout'] = rtrim(strtok(" "));
$equipment['revenue'] = rtrim(strtok(" "));
$equipment['price'] = rtrim(strtok(" "));
$equipment['hours'] = rtrim(strtok(" "));
$equipment['dep'] = rtrim(strtok(" ")); //SKIP
$equipment['maint'] = rtrim(strtok("/n")); //SKIP
printf ("The values should display as...\n");
printf ("| name | year | serial | charge | daysout | revenue | price | hours |\n");
foreach ($equipment as $key => $value)
{
if ($key == 'dep' || $index == 'maint') printf ("");
else
printf ("| %15s", $value);
}