php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28053 ADD 3 FUNCTIONS OF FILE
Submitted: 2004-04-19 06:38 UTC Modified: 2004-04-19 09:13 UTC
From: roberto at spadim dot com dot br Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: Irrelevant OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roberto at spadim dot com dot br
New email:
PHP Version: OS:

 

 [2004-04-19 06:38 UTC] roberto at spadim dot com dot br
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);
}
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-19 09:13 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri May 20 17:03:35 2022 UTC