GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, January 2, 2011

Reading A File In PHP

To open a file, type:
    $file = fopen("lola.txt","r") or exit("Cannot open the
            file");

To read one line, use:
    echo fgets($file);    // this pointer will advance one 
                          // per line

To check wheter reach end of file, type:
    feof($file);

To read a whole of file line by line, use:
    while(!feof($file)){
        echo fgets($file)."<br/>";
    }

To read a whole of file char by char, use:
    while(!feof($file)){
        echo fgetc($file)."<br/>";
    }
              
Share/Bookmark

No comments:

Post a Comment