Re: Reading semi formatted text file

From: Date: Mon, 24 Dec 2001 17:22:01 +0000
Subject: Re: Reading semi formatted text file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-78670@lists.php.net to get a copy of this message
$delimiter = "\t"; $file = "path/to/file/name.ext"; if($file = fopen($file, "r")) { $file_array = file($file); foreach($file_array AS $str) { $new_array[] = explode($delimiter, $file_array); } } now when you are done you will have an indexed array called new_array that contains your rows broken up into key=>value pairs. Jim ----- Original Message ----- From: "Chris Steitz" <csteitz@mpinet.net> To: <php-general@lists.php.net> Sent: Monday, December 24, 2001 9:12 AM Subject: [PHP] Reading semi formatted text file 201 PNCPS FINANCIAL ACCT 10027 3 8.00- 8.50 MWF GSB 400 I have a text file with rows similar to that above. I need to read the data in the rows into an array. fscanf likes to split the line into elements by spaces and I get 201,PNCPS,FINANCIAL,ACCT etc... and I need results like 201,PNCPS FINANCIAL ACCT,10027 etc... data[1]=201 data[2]=PNCPS FINANCIAL ACCT data[3]=10027 data[4]=3 data[5]=8.00 data[6]=8.50 data[7]=MWF data[8]=GSB 400 Can anybody provide any help on how to do this?

« previous php.general (#78670) next »