PHP file Operation method Summary,
Write the data in the database file:
<?php/** * Created by Phpstorm. * User:administrator * DATE:2015/6/29 * time:17:05 * */Header ("content-type:text/html; Charset=utf-8 "); Write Data $f = fopen (' Data ', ' w ');//Open the file fwrite ($f, ' Hello PHP ');//write to Fclose ($f);//Close file echo ' OK '; Windows environment temporarily does not consider permissions issues
After successful writing, you can see "OK" on the page.
Next, read the data in the file.
<?php/** * Created by Phpstorm. * User:administrator * DATE:2015/6/29 * time:17:05 */header ("content-type:text/html; Charset=utf-8 ");//read data$f = fopen (' Data ', ' R '); $content = Fgets ($f); Echo $content; fclose ($f);
How do I read more than one row of data?
Method One while:
<?php/** * Created by Phpstorm. * User:administrator * DATE:2015/6/29 * time:17:05 */header ("content-type:text/html; Charset=utf-8 "); $f = fopen (' Data ', ' r ');//Read multi-line data Whilewhile (!feof ($f)) {//feof () function to detect whether the end of the file has been reached $content = fgets ($f ); echo $content;} Fclose ($f);
Method two file_get_contents ():
echo file_get_contents (' data ');
The above mentioned is the whole content of this article, I hope you can like.
http://www.bkjia.com/PHPjc/1024924.html www.bkjia.com true http://www.bkjia.com/PHPjc/1024924.html techarticle PHP File Operation method Summary, write data in the file: Php/** * Created by Phpstorm. * User:administrator * DATE:2015/6/29 * time:17:05 */Hea Der ("Content-type:text/ht ...