From: roberto at spadim dot com dot br Operating system: ALL PHP version: Irrelevant PHP Bug Type: Feature/Change Request Bug description: ADD 3 FUNCTIONS OF FILE
Description: ------------ <? // get file size function fget_filesize(& $fp){ $old_point=ftell($fp); fseek($fp,0,SEEK_END); $size=ftell($fp); fseek($fp,$old_point,SEEK_SET); return($size); } // get number of rows function fget_num_lines(& $fp,$length=1024,$debug = false){ $old_point=ftell($fp);$buffer="";$pos=0; if ($debug) echo "BEGIN -- NUM LINES -- ftell->$old_point, buffer_length=$length\n"; // not working yet.. :_( // Linha UNIX => 10 // Linha WIN => 10,13 // Linha MAC => 13,10 fseek($fp,0,SEEK_SET); $num=0; while (true){ $num+=substr_count(fread($fp, $length),chr(10)); if (feof($fp)){ if ($debug) echo "***** End of File *****\n"; break; } } fseek($fp,$old_point,SEEK_SET); if ($debug) echo "*END* Num Lines: $num\n"; return($num); } // get one line function fget_line(& $fp,$length=1024,$debug = 0){ $old_point=ftell($fp);$buffer="";$pos=0; if ($debug>0) echo "BEGIN -- GET LINE -- ftell->$old_point, buffer_length=$length\n"; // Linha UNIX => 10 // Linha WIN => 10,13 // Linha MAC => 13,10 while (true){ $buffer.=fread ($fp, $length); $pos=strpos($buffer,chr(10)); if ($pos>0){ if (substr($buffer,$pos-1,1)==chr(13)){ // linha WIN if ($debug>1) echo "***** WIN Line *****\n"; $buffer=substr($buffer,0,$pos-1);$pos++; }elseif (substr($buffer,$pos+1,1)==chr(10)){ // linha MAC if ($debug>1) echo "***** MAC Line *****\n"; $buffer=substr($buffer,0,$pos);$pos+=2; }else{ if ($debug>1) echo "***** UNIX Line *****\n"; $buffer=substr($buffer,0,$pos);$pos++; } break; } if (feof($fp)){ if ($debug>1) echo "***** End of File *****\n"; $pos=-1; break; } $pos=0; } if ($pos==-1) fseek($fp,0,SEEK_END); else fseek($fp,$old_point+$pos,SEEK_SET); $new_point=ftell($fp); if ($debug>2) echo "BUFFER length->".strlen($buffer)."\n$buffer\n"; if ($debug>0) echo "*END* ftell->".ftell($fp)."\n"; return($buffer); } ?> -- Edit bug report at http://bugs.php.net/?id=28053&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28053&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28053&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28053&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28053&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28053&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28053&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28053&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28053&r=support Expected behavior: http://bugs.php.net/fix.php?id=28053&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28053&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28053&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28053&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28053&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28053&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28053&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28053&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28053&r=float