Home >Backend Development >PHP Problem >How to convert php files into strings
The file_get_contents() function can be used in php to convert the file into a string. It can read the contents of the file into a string. The syntax is "file_get_contents(file,include_path,context,start,maxlen) ".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use the file_get_contents() function to convert the file into a string.
The file_get_contents() function can read the contents of the file into a string. The syntax format of the function is as follows:
file_get_contents(file,include_path,context,start,maxlen)
The parameter description is as follows:
Note: When the file_get_contents() function fails to execute, it may return FALSE of Boolean type, or it may return a non-Boolean value (such as a null character). Therefore, the
===
operator is generally used to test the return value of this function.
Example:
There is such a text file, the content is:
Use the file_get_contents() function to convert the file into a string
<?php header("Content-type:text/html;charset=utf-8"); $file = 'test.txt'; $filestr = file_get_contents($file); if ($filestr) { echo $filestr; } else { echo '失败!'; } ?>
Output result:
Recommended learning: php training
The above is the detailed content of How to convert php files into strings. For more information, please follow other related articles on the PHP Chinese website!