PHP four

Why file contains?

In actual development, different logical operation functions need to be placed into different methods or a class or even a separate file. When we need to re-use, only need to use the file containing the operation, is well defined before it can be reused methods and functions.

advantage:

Improve code reusability

Improve write and maintain code

File contains:

Functions - includes failure - features.

Inlcude- returns a warning - file continues downward. Typically comprises a dynamic.

Require- a fatal mistake - the code will not continue down. Often contain important documents, never expect the entire code execution.

Include_once- returns a warning - the original process include the functionality, it will once detected, if the file had already been included too, it is no longer included.

Require_once- a fatal mistake - in addition to the original function will do a once detect, prevent, contain file repeatedly.

 

File Operations

Direct output file.

ReadFile (file name or file path [relative and absolute paths]) Return Value: The contents of bytes (one byte gbk encoding English Chinese accounted for two Chinese utf-8 symbols representing three spaces and occupy a).

open a file

file_get_contents (file name or file path) Return Value: Returns the contents of string type of file.

Get Content-Length: filesize (filename).

Read the file operation
basic processes: 1. Open the file => 2. file operation function provided php => 3. Close the file.

1. Open the File: fopen (file open path, the file open mode)
2. Read File: fread (resource, read length)
3. Close the file

file_put_contents (string $ file path, the write data String $]) written to the file
Function: a character string is written to the specified file. If the file does not exist, create file. It returns the byte length of write.

fwrite (resource $ resource file variable, string $ string written [, int length])

? < PHP 
     $ handle = tmpfile (); 
      
     $ numBytes = fwrite ($ handle, ' write temporary files ' ); 
     fclose ($ handle); 

    echo ' is written into the temporary file ' .. NumBytes $ ' bytes ' ;

 

Guess you like

Origin www.cnblogs.com/zhangzongke/p/11427060.html