RE: [PHP] Text file manipulation question.
| From: | Ford, Mike [LSS] | Date: | Tue, 15 Jul 2003 09:24:45 +0000 |
| Subject: | RE: [PHP] Text file manipulation question. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-155252@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Lloyd Bayley [mailto:lloyd@speednet.com.au]
> Sent: 15 July 2003 00:21
>
> I'm still in the learning stages of PHP and require some help
> with a small
> problem.
>
> I need to take a text file which looks like this (and no I
> can't get it
> output in CSV - damn and blast!)
>
> user1 26:48:59 6 logins 4:28:09 hrs/login
> user2 19:07:50 33 logins 0:34:46 hrs/login
> user3 12:12:04 18 logins 0:40:40 hrs/login
> user4 9:48:58 9 logins 1:05:26 hrs/login
>
>
> What I want to do (in PHP) is read the list in and search for
> a username,
> then display the associated statistics for that user.
> I'm hoping to get the logistics right first before wrapping
> it in a form.
> Breaking it up into a list works well, except for the fact
> that the spaces
> between elements are not necessarily the same. (bother!)
>
> Any suggestions, like for example to convert a string of
> spaces (greater
> than 1) to a comma perhaps to facilitate easier list building?
Try
preg_split('/ +/', $line);
to get an array of the values on a single line. You could easily do this to
each line of the file and build an array of arrays to give you the full data
structure. With a bit of judicious manipulation, you could even use the
usernames as the key of the outer array.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211