In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you PHP how to read the contents of the file, I hope you will learn something after reading this article, let's discuss it together!
1. Fread (): reads the open file, and the second parameter specifies the maximum number of bytes to be read.
$myfile = fopen ('testfile.txt', 'r') or die (' Unable to open fileholders'); echo fread ($myfile, filesize ('testfile.txt')); fclose ($myfile)
Fgetc (): reads a single character from a file, and after calling the fgetc () function, the file pointer moves to the next character.
$myfile = fopen ('testfile.txt', 'r') or die (' Unable to open fileholders'); echo fgetc ($myfile); fclose ($myfile)
3. Fgets (): reads a single line from the file, and you can specify the length of the line with the optional second parameter.
$myfile = fopen ('testfile.txt', 'r') or die (' Unable to open fileholders'); echo fgets ($myfile); fclose ($myfile)
4. The fgetss (): fgetss () function has the same function as the fgets () function, but the fgetss () function attempts to remove any HTML and PHP tags from the read text, and you can specify which tags are not removed with the optional third parameter.
$myfile = fopen ('testfile.txt', 'r') or die (' Unable to open fileholders'); while (! feof ($myfile)) {echo fgetss ($myfile, 1024,')
'). '
';} fclose ($myfile)
5. Feof (): check End-Of-File (EOF) and read the file line by line until the end of the file. Remote files or stream files are supported.
$myfile = fopen ('testfile.txt', 'r') or die (' Unable to open fileholders'); while (! feof ($myfile)) {echo fgets ($myfile). '
';} fclose ($myfile); # # read the remote file # $handle = fopen (' http://www.yisu.com', 'r'); $content ='; while (! feof ($handle)) {$content. = fread ($handle, 1024);} echo $content;fclose ($handle)
Fpassthru (): reads the given file pointer fseek () from the current location to EOF and writes the result to the output buffer.
$myfile = fopen ('testfile.txt', 'r'); fseek ($myfile, 1024); fpassthru ($myfile)
Readfile (): reads a file and writes it to the output buffer, returning the number of bytes read from the file.
$size = readfile ('testfile.txt'); echo $size; # returns bytes
8. File (): reads the contents of the file into an array. Each item in the array corresponds to a line in the file, including the newline character. When you do not need a line Terminator, you can use the rtrim () function to filter the newline character.
$myfile = file ('testfile.txt'); foreach ($myfile as $line = > $content) {echo' th'. ($line + 1) 'OK:'. $content. '
';}
9, file_get_contents (): read the whole file into a string, the performance is better, when accessing remote files, you can also set the timeout.
Echo file_get_contents ('testfile.txt'); # # read remote files # $timeout = stream_context_create (array (' http' = > array ('timeout' = > 1); echo file_get_contents (' http://www.yisu.com/', 0, $timeout) After reading this article, I believe you have a certain understanding of "how PHP reads the contents of files". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.