I have a php file with lines of data.
In order they are 1)pc serial number, 2)month purchased, 3)day of month purchased, 4)number of days serviced(taken away from users), and 4)original cost
each of these values are separated by a space
Is it possible to include 'pcinfo.php' into another php file and use strtok (I'm sure with rtrim) to retrieve all of the data one line at a time (or 4 values at a time) using a While Loop instead of print for each line?
I've been experimenting for days, but am getting very little. Thanks
Ambitious while loop
Moderator: General Moderators
Re: Ambitious while loop
You could look into file() and explode().
-
JasonGreen
- Forum Newbie
- Posts: 7
- Joined: Sun Sep 13, 2009 10:22 am
Re: Ambitious while loop
Thanks for the response. It doesn't seems like an array would be optimal, unless I'm doing it wrong. This original php file of data is in php, not text. Which is why I was attempting to use strtok, my goal is to use as little code as possible to display the data.
Thanks
Thanks
-
JasonGreen
- Forum Newbie
- Posts: 7
- Joined: Sun Sep 13, 2009 10:22 am
Re: Ambitious while loop
Sorry for the confusion. I understand and yo make a valid point. Let me show you a bit of what the file looks like
<?php
$serialpurchase =
"GXC1233 5 9 19 1124.95
GXB1F65 3 7 5 795.13
GXF1977 9 4 2 1229.
FXG4986 9 17 5 497.35
etc.
this is why I'd like an easy way to tug it out. Thanks again.
<?php
$serialpurchase =
"GXC1233 5 9 19 1124.95
GXB1F65 3 7 5 795.13
GXF1977 9 4 2 1229.
FXG4986 9 17 5 497.35
etc.
this is why I'd like an easy way to tug it out. Thanks again.
Re: Ambitious while loop
Like this:
Although I think maybe you should be using a database for this..
Code: Select all
<?php
foreach(file('test.php') as $line)
{
if(preg_match('/[^A-Za-z0-9\s\.]+/', $line) || substr_count($line, ' ') != 4)
continue;
list(
$serial_number,
$month_purchased,
$day_purchased,
$days_serviced,
$original_cost
) = explode(' ', $line);
//do whatever with the variables
}
?>