PHP Learning Series 6 file operations: fopen (); fopen (path, mode); if fopen opens a remote file, check php. ini. in this file, you can disable this function by disabling the allow_url_fopen command. Before fopen, use the @ symbol to tell php to suppress all errors caused by this function call. PHP Learning Series 6
File operations:
Fopen ();
Fopen (path, mode );
If fopen encounters a problem when opening the remote file, check php. ini. in this file, you can disable this function by disabling the allow_url_fopen command.
Before fopen, use the @ symbol to tell php to suppress all errors caused by this function call.
Fwrite () or fputs () can write files
Fwrite ($ fp, $ outputstring), a replacement function of the fwrite () function is file_put_contents ().
Close the file:
Fclose ($ fp );
Read files
Step: open the file, read the file, and close the file.
Fopen (file, 'RB ')
Feof () determines the end of the file
Fgets (), fgetss (), fgetcsv ()
For example: $ order = fgets ($ fp, 999): You can read a line of content from the file until you read the line break, or the end of the file, or read 998B from the file. the maximum length that can be read is the specified length minus 1B.
Fgetss () can filter php and html tags contained in strings.
Fgetcsv ()
Read the entire file: readfile (), fpassthru (), file ()
Read a character: fgetc ()
Read one character from a file at a time.
Fread (): read any length
Other useful file operation functions:
File_exists (): Check whether the file exists.
Filesize (): view the size of a file, in bytes.
Nl2br () converts the \ n character output to the HTML line break (
)
Unlink () deletes an object.
Rewind (), fseek () and ftell ()
Rewind (): reset the file pointer to the beginning of the file.
Ftell (): Report the current position of the file pointer in bytes.
Fseek (resource fp, int offset [, int whence]). The fseek () function can move the file pointer fp from The hence position to the offset byte. whence is an optional parameter, the default value SEEK_SET indicates the start of the file.
Flock (): locks the object. if the object is locked successfully, true is returned. if the object fails, false is returned.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.