At 06.05.01  23:28, you wrote:
>:Please forgive me for having posted this more than once.  I am trying to
>reword it here to make it more plain.
>---------------
>I have a fixed length text file I'm trying to import and send into MySQL.
>A record line is about 1600 characters long and includes many blank spaces.
>I thought by using file('FILENAME.TXT') I would have a nice neat array of
>each record in the file based on each line being a record.
>Here's an example txt file:
>ABCDEFG HIJ     KLMNOP
>YASFSEFAFSAFSDFFDS
>(notice the 4 spaces after J and before K on line 1 of the above text file)
>So, I went on breaking up the line into fields by doing this:
>$ra=$recordArray=file('FILENAME.TXT');
>for($index=0;$index<count($ra);$index++) {
>$FIELD_1[]=substr($ra[$index],0,18);
>$FIELD_2[]=substr($ra[$index],18,19);
>$FIELD_3[]=substr($ra[$index],19,20);
>}
>I expected that to give me 3 fields on line 1 that would have looked like
>this:
>FIELD 1 = ABCDEFG HIJ    KLM
>FIELD 2 = N
>FIELD 3 = OP
>Instead it gave me:
>FIELD 1 = ABCDEFG HIJ KLMOP
>FIELD 2 =
>FIELD 3 =
>because it stripped out the empty spaces along the way.
>Can you tell me how I might prevent that from happening?
>Thanks very much,
>Jay Lepore
>[EMAIL PROTECTED]
Hello Jay
Iīm a little "old style" an read about file() the first time. I havenīt 
used file yet.
For your problem try this "old style method, which I use with success.
$fp=fopen("filename.txt","r")
while(! feof($fp))
{
         $buffer=fgets($fp,$qty_to_read);
         $part[1]=substr($buffer,0,18);
         $part[2]=substr($buffer,0,18);
         ....
}
fclose($fp);
You would like tohave an easier job with extracting your sentences(when the 
appear in a logical order)
if you use an array, where to chop them
$where_to_chop=array(18,25,36,72);
for ($i=0; $i < count($where_to_chop);$i++)
{
         $part[$i]=substr($buffer,$where_to_chop[$i],$where_to_chop[$i+1]);
         ....
         $i++;
}
HTH Oliver


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to