Page 1 of 1

help in my fixed-width text file & php

Posted: Sat Jan 27, 2007 12:21 am
by mfmondragon
hi guys, id like to ask how can i do this:

1. the text file should be uploaded by the user (is there any codes you can provide)

2. i have a text files that is not comma-delimited, only fixed width. though basically i just need 2 - 3 fields to be imported to the database. (the reason why i need this because of the nature of legacy database we're using... btrieve, that's why i just rely to text files being generated)

here's the sample data:

XXXXX 1004567 I09890990 DELACRUZ, JUAN 01/09/06
XXXXX 1004568 I09890990 DELACRUZ, JUAN 01/09/06
XXXXX 1004569 I09890990 DELACRUZ, JUAN 01/09/06
XXXXX 1004575 I09890990 DELACRUZ, JUAN 01/09/06

assuming that i need the records for the second & third column? how can i get those?

i hope you could help me... thanks!

Posted: Sat Jan 27, 2007 12:31 am
by volka

Posted: Mon Jan 29, 2007 12:51 am
by mfmondragon
can you show sample code pls? the first column doesn't always start by the way in 'XX' i just hide it from its real value.

Posted: Mon Jan 29, 2007 1:14 am
by mfmondragon
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


oops, i got it working now... thanks! but i just need to third row.  how can i get and pass it into a variable?

here's my code...

Code: Select all

<?php

$fp = @fopen("studlst.txt", "rb") or die("Couldn't open file");
$data = fread($fp, filesize($fp));

while(!feof($fp))
{
	$data .= fgets($fp);
}

fclose($fp);
$values = explode("\r\n", $data);

foreach ($values as $val)
{
	$read = sscanf($val,"%24s %s %d");
	print_r ($read);
	echo ("<br />");
}

?>
thanks again!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]