Jump to content


txtfile handling


2 replies to this topic

#1 Marxx

    Young Padawan

  • Members
  • Pip
  • 116 posts
  • Gender:Male
  • Location:Finland

Posted 25 September 2007 - 12:38 PM

Hello all!

Need some help whit here (again..)
I have this txt file where is about 3000 lines data and now I have to collect this data.

This is what it looks like:
1|00650|
1|Helsinki|
2|00100|
2|Helsinki|
3|01210|
3|Vantaa|
4|02440|
4|Kirkkonummi|

Now, first there is zip code and then location. Both information is under same ID numbers and question is:
How can I collect this data so I can define that under same ID is actually 2 information?

So It looks something like this:
1|00650|Helsinki
2|00100|Helsinki
3|01210|Vantaa
4|02440|Kirkkonummi

Output don't have to be like that but if I just could define those data somehow..

$id = $data[0];
$zipcode = $data[1];
$location = $data[2];

This way I can insert those into MySql .. :lol:

I hope this was understandable and if someone just could quide me here please..



Thanks - Marxx

#2 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 25 September 2007 - 02:52 PM

explode or preg_match_allshould help you

Edited by Mr. Jay, 25 September 2007 - 04:19 PM.


#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 27 September 2007 - 11:56 AM

/* Note, this assumes you're working one line at a time, with the current line being = $line; */
$data = explode('|', $line);
$parsed_data[$data[0]] = $data[1];






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users