note 41663 deleted from function.fgets by irchtml
| From: | irchtml@php.net | Date: | Mon, 19 Apr 2004 00:08:05 +0000 |
| Subject: | note 41663 deleted from function.fgets by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-68306@lists.php.net to get a copy of this message | ||
Note Submitter: roberto@spadim.com.br
----
to get one line per function you can use:
changing debug to 0,1,2,3 you can have more info about function
function fget_line(& $fp,$length=4096,$debug = 0){
$old_point=ftell($fp);$buffer="";$pos=0;
// Linha UNIX => 10
// Linha WIN => 10,13
// Linha MAC => 13,10
if ($debug>0)
echo "BEGIN ftell->$old_point, buffer_length=$length\n";
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 "***** No Line *****\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->$new_point\n";
return($buffer);
}