views:

49

answers:

2

Hello, I am new to php and am asking for some coding help. I have little experience with php and have gone to the php.net site and read couple books to get some ideas on how to perform this task.

There seems to be many functions and I am confused on what would be the best fit. (i.e. fgetcsv, explode(), regex??) for extracting data in the file. THen I would need assistance printing/display this information in orderly fashion.

Here is what I need to do:

  • import, readin txt file that is delimited (see sample)

The attributes are not always ordered and some records will have missing attributes.

  • Dynamically create a web table (html) to present this data

Sample records:

attribute1=value;attribute2=value;attribute3=value;attribute4=value;
attribute1=value;attribute2=value;attribute4=value;
attribute1=value;attribute2=value;attribute3=value;

How do I go about this? What would be best practice for this? From my research it seems I would create an array? multidimensional? Thank you for your time and insight and i hope my question is clear.

A: 

i would first use the file() method, which will give you an array with each line as an element. Then a couple of explodes and loops to get through it all,first exploding on ';', then loop through each of these and explode on '='.

GSto
@GSto - ok, thanks. I will give it a shot. Where else to find good examples of using these? A good example would help.
cjd143SD
would this also setup well for using the preg_match_all function?
cjd143SD
+4  A: 

Seems like homework, if so best to tag it as such.

You will want to look into file(), foreach() and explode() given that it is delimited by ;

The number of attributes should not matter if they are missing, but all depends on how you setup the display data. Given that they are missing though, you will need know what is the largest amount of attributes to setup the table correctly and not cause issues.

Best of luck!

Brad F Jacobs
@premiso - thank you for reply. display data would be simple table. where (4) of the main headers are in first row. Then each value is placed under that header and if there is no value, then we can have a empty cell.
cjd143SD