|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-04-19 09:13 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
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); } ?>