01<?php 02 03file('path/to/file.txt'); 04 05?> 06 07but well, here you go ... 08 09<?php 10 11// GetLine 12// Obtain the next line in a given file by reading each character until a \r or \n is reached. 13 14// @param file a handle returned from fopen for our file. 15// @return string the next line in the file. 16 17functiongetLine($file) 18{ 19 20// iterate over each character in line. 21while(!feof($file)) 22{ 23 24// append the character to the buffer. 25$character=fgetc($file); 26$buffer.=$character; 27 28// check for end of line. 29if(($character=="\n")or($character=="\r")) 30{ 31 32// checks if the next character is part of the line ending, as in 33// the case of windows '\r\n' files, or not as in the case of 34// mac classic '\r', and unix/os x '\n' files. 35$character=fgetc($file); 36if($character=="\n") 37{ 38 39// part of line ending, append to buffer. 40$buffer.=$character; 41 42}else{ 43 44// not part of line ending, roll back file pointer. 45fseek($file,-1,SEEK_CUR); 46} 47 48// end of line, so stop reading. 49break; 50} 51} 52// return the line buffer. 53return$buffer; 54} 55 56?>