PHP Programming Part 6

advertisement
PHP Programming Part 6
Printing to Files with PHP
1. In this example, you use the PHP file_put_contents() function. Briefly describe this function.
Hint: Consult W3Schools or the PHP manual.
The file_put_contents() writes a string to a file.
This function follows these rules when accessing a file:
1.
2.
3.
4.
5.
6.
7.
If FILE_USE_INCLUDE_PATH is set, check the include path for a copy of *filename*
Create the file if it does not exist
Open the file
Lock the file if LOCK_EX is set
If FILE_APPEND is set, move to the end of the file. Otherwise, clear the file content
Write the data into the file
Close the file and release any locks
This function returns the number of character written into the file on success, or FALSE on
failure.(w3schools.com)
1. What is a CSV file? Why would you want to use one?
A CSV is a comma separated values file, which allows data to be saved in a table structured
format. CSVs look like a garden-variety spreadsheet but with a .csv extension (Traditionally they
take the form of a text file containing information separated by commas, hence the name). CSV
files can be used with any spreadsheet program, such as Microsoft Excel, Open Office Calc, or
Google Spreadsheets. They differ from other spreadsheet file types in that you can only have a
single sheet in a file, they can not save cell, column, or row styling, and can not save forumlas.
(Bigcommerce, 15)
Download