Professional Web Applications Themes

Text file manipulation question. - PHP Development

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 ...

  1. #1

    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! :-)


    Lloyd Bayley Guest

  2. #2

    Default Re: [PHP] Text file manipulation question.

    Lloyd Bayley <lloydspeednet.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
    --

    Curt Zirzow Guest

  3. #3

    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 <lloydspeednet.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 ([url]http://www.php.net/[/url])
    >To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]


    Lloyd Bayley Guest

Similar Threads

  1. Text Manipulation with Javascript
    By Permana_online in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: September 1st, 04:09 AM
  2. R&D Question - Image Manipulation w/ Flex?
    By bim in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: August 19th, 10:30 PM
  3. Another String Manipulation Question
    By Bill in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: February 21st, 03:31 AM
  4. Direct experience of text manipulation in Perl/TCL?
    By Selwyn Leeke in forum PERL Miscellaneous
    Replies: 5
    Last Post: September 15th, 03:43 PM
  5. [PHP] Text file manipulation question.
    By Mike Ford in forum PHP Development
    Replies: 0
    Last Post: July 15th, 09:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139