Class 7 – Advanced Homework Assignment (optional)
Posted: March 28th, 2009 | Author: amos | Filed under: assignments, php | Tags: class 7 | No Comments »If you are finished with the in-class assignment, and you feel comfortable with the material in the tutorials, here is an optional advanced assignment to keep you busy: convert the in-class assignment so that the product info is being pulled from an external plain-text file into a PHP multidimensional array.
You will have to modify your code so that the product info is no longer hard-coded in the PHP script, but the basic structure of how you loop through the multidimensional array should remain the same.
You may want to peek into the file_readwrite/read.php script on the server, which shows how to read line by line out of a text file.
I suggest that each line in your text file use delimiters, like commas, to separate the various fields of data that you’re storing. So the contents of each line in this text file would hold all the fields necessary for one product. The fields might look something like:
<product_id>,<product title>,<product description>,<product_link>,<product_price>
So, for example:
1,Big Cookie,This is a really big cookie, http://onepotcooking.com/somefile,$99.00
You may find the PHP built-in implode() and explode() functions to be useful for dealing with string delimiters, such as the comma in this case.
You’ll want to pay attention to the PHP – File Read pages in the tutorials as general info for dealing with files.
Related posts:
- Class 8 – Advanced assignment & very advanced assignment
- Class 2 – Homework Assignment
- Class 3 – Homework Assignment
- Class 3 – Homework Assignment
Leave a Reply