Bluehost.com Web Hosting $6.95

Text file manipulation question.

This is a discussion on Text file manipulation question. within the PHP General forums, part of the PHP Programming Forums category; Greetings All! I'm still in the learning stages of PHP and require some help with a small problem. I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-15-2003
Lloyd Bayley
 
Posts: n/a
Default Text file manipulation question.

Greetings All!

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?


Cheers,

Lloyd. :-)
PS: I'm an old Coldfusion programmer who has seen the light....so I have
the logics but can't translate it to PHP...therefore, I'm here! :-)


Reply With Quote
  #2 (permalink)  
Old 07-15-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] Text file manipulation question.

Lloyd Bayley <lloyd@speednet.com.au> wrote:
> Greetings All!
>
> 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?



Assuming you read each line of the file into a variable called $line:
//replace more than one space to a comma
$newline = ereg_replace(' +', ',', $line);

Translates:
user1 26:48:59 6 logins 4:28:09 hrs/login

To:
user1,26:48:59,6 logins,4:28:09 hrs/login


>
> Cheers,
>
> Lloyd. :-)
> PS: I'm an old Coldfusion programmer who has seen the light....so I have
> the logics but can't translate it to PHP...therefore, I'm here! :-)


Good to hear that!

HTH,

Curt
--

Reply With Quote
  #3 (permalink)  
Old 07-15-2003
Lloyd Bayley
 
Posts: n/a
Default Re: [PHP] Text file manipulation question.

Thankyou! That works a treat!

Lloyd. :-)

At 11:36 PM 14/07/2003 +0000, you wrote:
>Lloyd Bayley <lloyd@speednet.com.au> wrote:
> > Greetings All!
> >
> > 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?

>
>
> Assuming you read each line of the file into a variable called $line:
> //replace more than one space to a comma
> $newline = ereg_replace(' +', ',', $line);
>
> Translates:
> user1 26:48:59 6 logins 4:28:09 hrs/login
>
> To:
> user1,26:48:59,6 logins,4:28:09 hrs/login
>
>
> >
> > Cheers,
> >
> > Lloyd. :-)
> > PS: I'm an old Coldfusion programmer who has seen the light....so I have
> > the logics but can't translate it to PHP...therefore, I'm here! :-)

>
> Good to hear that!
>
>HTH,
>
>Curt
>--
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php




Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0