Jump to content

need help with read data from textfile


fifin04

Recommended Posts

Hi ..

I just need ur expertise opinion guys...regarding my attempt to read the content of the texfile in everyline then push into array after going through some filtering process...my problem here is how to optimize this code since my code currently using substr to split the string in each line in order to seprated in different category...I hope u guys will show me the smart way how to loop the data in textfile...soryy for being such noob..

//here my php code
[code=php:0]

$pathtxt = "p151120091.jpp.txt";
//array to store data from textfile
$record = array();

if ($fh = fopen($pathtxt, "r")){
	while (!feof($fh)) {
		if ($dt = fgets($fh)) {
			$lines++;
			$pymt_location = substr($dt, 0, 4);		 
			$machine_no 	= substr($dt, 4, 2); 	
			$pymt_date 		= substr($dt, 6, ; 	
			$receipt_num 	= substr($dt, 14, 6); 	
			$revenue_code 	= substr($dt, 20, 4); 	
			$acc_no 		= substr($dt, 24, 14); 	
			$pymt_amount 	= substr($dt, 38, 10);	 
			$pymt_mode 		= substr($dt, 48, 1); 	
			$id_cashier 	= substr($dt, 49, 2); 	
			$cheque_no 		= substr($dt, 51, 16); 	

			//filter here
			if($revenue_code == "0020"){
				array_push($record,array($pymt_location,$machine_no,$pymt_date,$receipt_num,$revenue_code,$acc_no,$pymt_amount,$pymt_mode,$id_cashier,$cheque_no));
			}
		}
	}//end while
	//echo total record here
	echo count($record)." Total data in array after filter<br/>\n";
	echo $lines." the sum of all data in textfile";
}else{
	echo "can read textfile !!";
}

 

and here are my sample textfile

C07 41290420082138140020012400885359030000030365102                
C07 412904200821381500202000370904019 0000004605102                
C07 41290420082138160018D908211360402 0000013750102                
C07 4129042008213817005110000437003   00000360008024539660002057167
C07 4129042008213818002010000669839   00000300008024539660002057167
C07 4129042008213819005030002379369   0000025700102                
C07 4129042008213820005030002379330   0000095400102                
C07 412904200821382100172000278403010 0000000855102                
C07 412904200821382200172000278047012 0000004760102                
C07 412904200821382300170000045738013 0000001025102                
C07 41290420082138240016012400749311090000009330102                
C07 4129042008213825005030006801066   00000275008024293132690537260
C07 4129042008213826005030006801066   00000270008024293132690537260
C07 4129042008213827005030002486126   0000009920102                
C07 4129042008213828005030002340864   000004880030201323233   

 

Hope will get most optimize way in order to loop the data in textfile..really need ur guys expertise opinion...tq..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.