How to use PHP to read files

Source: Internet
Author: User
I heard that I want to discuss it. I would like to invite you to write this article. I hope you will forgive me for a limited level. :) now many of my friends have their own free space (after all, there are still many poor people in China ), the mean ISP does not provide MYSQL, so smart friends choose ---- (FILE Table database format). In fact, it is my own SyntaxHighlighter. all ();

I heard that I want to discuss it. I would like to invite you to write this article. I hope you will forgive me for a limited level. :) now many of my friends have their own free space (after all, there are still many poor people in China ), the mean ISP does not provide MYSQL, so smart friends choose ---- (FILE Table database format), which is defined by myself ~ Access is a file table Database. if you add a DSN to your machine, you can ACCESS data in your Access through ODBC. However, ISP cannot configure DSN for you in the network ~, Therefore, we chose to use files to save the data file data. Considerations: 1. implement some database functions-(don't expect something like a database ~) 2. data security and stability-(requires Program Support) 3. convenient maintenance-(too up) it seems not good to write the content here once ~ Let's start with the basics ~ First, you need a piece of text to save. you can create 1. echo "info"> File.txt 2, fopen ("file.txt ", "w/w +/a +"); 3. the first implementation of upload your FILE.txt is exec () --- check whether this function is disabled in PHPINFO () before using it ~ Second, it is basically supported. I don't think any ISP can give it to disable! Third, upload your local file ~ After a file is created, the following operations on the file are simple-read/write updates/deletions are included in the file. 1. here we will first talk about the reading information of the file that needs to be read after it is saved to the data file. if it is not read, it is useless to write more, PHP provides several methods to read files: 1. fopen 2. file 3. fsockopen. the specific examples are as follows: 1. $ fp = fopen ("text.txt", "method "); where METHOD is r-open the file in read-only mode; read the first character of the mark in the file (equivalent to the file pointer in C ). r +-open the file in read/write mode; read the first character of the mark in the file (equivalent to the file pointer in C ). w-open the file in write mode; place the write mark in the first place, and set the file size to a minimum of-0 bytes. if the opened file does not exist, create the file to provide write. w +-open the file in read/write mode; place the write mark first, and set the file size to a minimum of-0 bytes. if the opened file does not exist, create the file to provide write a-open the file in write-only mode; put the mark in the file's EOF, all added information The file will be created at the end of the file if the file does not exist. A +-open the file in read/write mode. Place the mark in the file's EOF. all added information will be at the end of the file. if the file does not exist, the file will be created. This function can also be opened http://,ftp://,udp:// File where http://,udp:// It should be opened in read mode, otherwise there will be an error in this function, there is a small prompt: Do not open http: // file itself, otherwise there will be a little trouble ~ 2. var $ fp = array (); $ fp = file ("text.txt"); the meaning of this expression is white at first glance. file () is to read all the files, and then store them in an array. if each file appears (press enter to wrap), the file function of one element in the array has only one parameter file (filename)
";} Print" $ testfile text content: ". $ info;?> 3, ";} Else {fputs ($ fp," GET/HTTP/1.0 Host: www.php.net "); while (! Feof ($ fp) {echo fgets ($ fp, 128) ;}fclose ($ fp) ;}?> ";}Else {fwrite ($ fp," "); echo fread ($ fp, 26); fclose ($ fp) ;}?> The reading of the file is now here. below is the writing of the file ....

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.