[PHP] while loops [ newbie ]

2001-05-17 Thread charles

be forewarned that a bash fan is writing this message with little to no
perl/c++ experience.

i have a file $file that is full of usernames and descriptions, one per
line. i have another variable $username that i would like to compare against
each line in the file and remove the line that matches the
username field identically.

$filename

charles routers
craig   systems
tonyportmasters

i would think that a while loop could do this and possibly write the
output, minus the line i want to take away to a temp file and then copy it
over. in bash i would use a statement like:

while read i; do
  < blah >
done < $filename > $filename.tmp

however i am not certain how to read in the contents of a file for
comparison within a while loop. this is just going to be an uphill thread
since my next question will be for the < blah > portion :)

thanks in advance -charles

-- 
**
There are two major products to come out of Berkeley:
LSD and UNIX.  We don't believe this to be a coincidence.
**


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] while loops [ newbie ]

2001-05-17 Thread Christian Reiniger

On Thursday 17 May 2001 13:58, [EMAIL PROTECTED] wrote:

> i would think that a while loop could do this and possibly write the
> output, minus the line i want to take away to a temp file and then copy
> it over. in bash i would use a statement like:
>
> while read i; do
>   < blah >
> done < $filename > $filename.tmp
>
> however i am not certain how to read in the contents of a file for
> comparison within a while loop. this is just going to be an uphill
> thread since my next question will be for the < blah > portion :)

http://php.net/file
http://php.net/foreach
http://php.net/fopen
http://php.net/fwrite

Should get you started.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

...1000100011010101101010110100111010113...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] while loops [ newbie ]

2001-05-17 Thread Steve Werby

<[EMAIL PROTECTED]> wrote:
> i have a file $file that is full of usernames and descriptions, one per
> line. i have another variable $username that i would like to compare
against
> each line in the file and remove the line that matches the
> username field identically.
>
> $filename
>
> charles routers
> craig systems
> tony portmasters
>
> i would think that a while loop could do this and possibly write the
> output, minus the line i want to take away to a temp file and then copy it
> over. in bash i would use a statement like:
>
> while read i; do
>   < blah >
> done < $filename > $filename.tmp
>
> however i am not certain how to read in the contents of a file for
> comparison within a while loop. this is just going to be an uphill thread
> since my next question will be for the < blah > portion :)

Use fopen() to open the file, while ( ! feof( $fp ) ) to loop through the
file until the end of it is reached and fgets() to read one line at a time.
Use explode() to grab the first word on each line, compare it to your other
variable and write each line to a new variable if it doesn't match.  Then
use fwrite to write to a temporary file and copy that file over the
original.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]