faqts : Computers : Programming : Languages : PHP : General Information : About PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 33 people (85%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

I need to read a file line by line, add something different to ea. line, then write it to file

May 7th, 2002 22:27
David Price, Richard Choy,


Refer to the filesystem functions in the PHP manual available at 
http://www.php.net/manual/en/ref.filesystem.php

Basicly you want to do this

$fs = fopen( 'filesource', 'r' );
$fd = fopen( 'filedestination', 'w' );

while( ! feof( $fs ) )
{
    $tmp = fgets( $fs );

    # replace this line with whatever you want to do to each line
    $tmp = process_line( $tmp );

    fputs( $fd, $tmp );
}

fclose( $fd );
fclose( $fs );