Chapter 2 Storing and Retrieving Data Flashcards
Define and Show: fopen()
Opens a file.
$fp = fopen(“$DOCUMENT_ROOT/bobs/orders.txt, ‘ab’);
fopen file mode: r
Read. Open the file for reading, beginning from the star of the file.
fopen file mode: r+
Read. Open the file for reading and writing, beginning from the start of the file.
fopen file mode: w
Write. Open the file for writing, beginning from the start of the file. If the file exists, delete the existing contents. If it does not exist, try to create it.
fopen file mode: w+
Write. Open the file for writing and reading, beginning from the start of the file. If the file already exists, delete the existing contents. If it does not exist, try to create it.
fopen file mode: x
Cautious write. Open the file for writing, beginning from the start of the file. If the file already exists, it will not be opened, fopen() will return false, and PHP will generate a warning.
fopen file mode: x+
Cautious write. Open the file for writing and reading, beginning from the start of the file. If the file already exists, it will not be opened, fopen() will return false, and PHP will generate a warning.
fopen file mode: a
Append. Open the file for appending (writing) only, starting from the end of the existing contents, if any. If it does not exist, try to create it.
fopen file mode: a+
Append. Open the file for appending (writing) and reading, starting from the end of the existing contents, if any. If it does not exist, try to create it.
fopen file mode: b
Binary. Used in conjunction with one of the other modes. You might want to use this mode if your file system differentiates between binary and text file. Windows systems differentiate; Unix systems do not. The PHP developers recommend you always us this option for maximum portability. It is the default mode.
fopen file mode: t
Text. Used in conjunction with one of the other modes. This mode is an option only in Windows systems. It is not recommended except before you have ported your code to work with the b option.
Define and Show: fwrite() or puts()
Write to a file.
fwrite($fp, $outputstring);
Define and Show: @
Error suppression operator is used to suppress Wordpresses default error message.
@ $fp = fopen(“$DOCUMENT_ROOT/bobs/orders.txt, ‘ab’);
Define and Show: file_put_contents()
This function writes the string to the file without any need for an fopen() function call.
Define and Show: fclose()
Close a file.
fclose($fp);