Home > Backend Development > PHP Tutorial > How to use PHP to read files_PHP Tutorial

How to use PHP to read files_PHP Tutorial

WBOY
Release: 2016-07-13 17:26:32
Original
888 people have browsed it

I heard that there is going to be a discussion, so I invited a friend to write about it. I hope you can forgive me for my limited level:) Nowadays, many friends have their own free space (after all, there are still many poor people in China), and stingy ISPs do not provide MYSQL, so smart friends I chose ---- (FILE file table database format), which is actually my personal definition~ Access is a file table database. If you just add a DSN to your machine, you can access it through ODBC. Data within your ACCESS. However, it is impossible for ISP to configure DSN for you on the network~, so we chose to use files to save data FILE DATA. Taking into account the content: 1. Realize some functions of the database--(don't expect to be like the database~) 2. Data security and stability--(needs program support) 3. Convenience of maintenance--(TOO UP) If these contents are written at once, Here, it seems not very good~ Let’s start with the basics~ First you need a text to save, you can create it in the following ways 1. echo "info" >> File.txt 2. fopen("file.txt ","w/w+/a/a+"); 3. The first implementation of UPLOAD YOUR FILE.txt is exec() --- before using it, check whether this function is disabled in PHPINFO()~ The second one is basically the same Yes, I don’t think any ISP will disable this! Third, brother, upload your local files~ After creating the file, the following is the operation of the file. The operation of the file is simply-read/write, including update/deletion. 1. Here we first talk about the reading information of the file that needs to be read out after it is saved in the data file. If it is not read out, no matter how much you write, it will be useless. PHP provides several ways to read files 1, fopen 2, file 3 , The specific examples of fsockopen are excerpted 1. $fp=fopen("text.txt","method"); where METHOD is r - open the file in read-only mode; the read mark is in the first character of the file (equivalent to (equivalent to the file pointer in C). r+ - Open the file for reading/writing; the read flag is placed at the first character of the file (equivalent to the file pointer in C). w - Open the file for writing; place the write flag in the first place, while setting the file size to a minimum of -0 bytes. If the opened file does not exist, this file is created to provide for writing. w+ - opens the file for read/write; puts the write flag in first place, while placing the file The size is set to a minimum of -0 bytes. If the opened file does not exist, this file is created to provide writing a - Open the file in write-only mode; place the flag at the EOF of the file and all added information will be at the end of the file , if the file does not exist, create the file. a+ - Opens the file for reading/writing; puts the flag at the EOF of the file and all added information will be at the end of the file, creating the file if it does not exist. This function can also open http://, ftp://, udp:// files. http://, udp:// should be opened in read mode, otherwise an error will occur. Here is a small tip for this function: Please do not open the http:// file itself, otherwise there will be a little trouble ~ $testfile="test.txt"; $fp=fopen($testfile,r); $outputtext=fgets($testfile,filesize($testfile)); echo "$testfile文本内容:".$outputtext; fclose($fp) ?> 2. var $fp=array(); $fp=file("text.txt"); Let’s take a look at the meaning of this expression As the name suggests, file() reads all files and then stores them in an array. Each time a file appears in the file, (carriage return and line feed), then there is one more element in the array. The file function has only one parameter, file(filename) $testfile="test.txt"; $fp=file($testfile); while($int_a=0;$int_a
"; } 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 ends here for the time being, and the next step is to write the file....

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531951.htmlTechArticleI heard that there will be a discussion, so a friend invited me to write about it. I hope you can forgive me, my level is limited:) Nowadays, many friends have their own Free space (after all, there are still many poor people in China), and the stingy IS...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template