Hi,

Alexander Gruber <[EMAIL PROTECTED]> wrote: 
> Hi together,
> 
> iエm currently working on a php script to read a txt file into a mysql 
> database. but i have several problems i donエt know how to fix.
> the file looks like the following example:
> 
> category 1
>     Data1 ::#:: 27
>     Data2 ::#:: 0
>     Data3 ::#:: (152)
> 
> category 2
>     Data1 ::#:: 2b3
>     Data2 ::#:: 234
>     Data3 ::#:: (1)
> 
> the qeuestion i have is how can i parse each line and use the 
> "category" fields as identifier for the tables, the left side of ::#:: 
> as identifier for the rowエs and the right side as the data. the 
> problem is collecting the several pieces of data in different 
> variables.

Well, one way you could do this is:
1. Use file() to read your txt file and the contents into an array.
2. Loop thru the array using foreach()
3. While you're looping, check each value, perhaps using strstr(),
   if it has "category" then assign it as identifier. If not, you're 
   probably on the row:data line so use explode() to explode the value 
   into two parts, using "::#::" as your separator. Assign them again 
   accordingly.

Then, after that, you can now do something with the variables...

> perhaps someone can give me some help or a url where i can find some 
> documentation.

Check the manual for those functions.

NOTE: There must be some other, more elegant, way of doing it but this 
is just to give you an idea.

HTH,

- E

__________________________________________________
Do You Yahoo!?
Yahoo! BB is Broadband by Yahoo!  http://bb.yahoo.co.jp/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to