Home > Backend Development > PHP Tutorial > The difference between file_get_contents() and file_PHP tutorial

The difference between file_get_contents() and file_PHP tutorial

WBOY
Release: 2016-07-13 10:52:35
Original
853 people have browsed it

I didn’t notice before that I could use the file function. Today I was making a PHP project to import txt text data into the database. At first, I used file_get_contents() to save the data to variables and then use explode to process it, but later on I found about the usage of file function on the Internet, and I really think that the file function is really beautiful and easy to use. Let’s take a look

Okay, let’s look at an example. Let’s look at the file_get_contents() function first. Now I want to save the contents of the text file a.txt into a data. Below is the content of a.txt as follows.

aaaaaa

bbbbbb

bbbbccc

Okay, just these three lines, now let’s look at the operation method of file_get_contents.

$content = file_get_content('a,txt');

$temp =str_replace(chr(13),'|',$content);
 
$arr =explode('|',$temp);

It’s not much more than just three lines, so let’s take a look at the file function.

$content = file('a.txt');

It’s done, the effect is exactly the same as above.

Haha, in fact, there are many functions in PHP that we often don’t use. We don’t need to remember them, as long as we know that they exist,

Okay, one final statement: Please indicate when reprinting original articles on this site: www.111cn.cn/phper/php.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632480.htmlTechArticleI didn’t notice that you can use the file function before. Today I am making a php to import txt text data into the database. I use file_get_contents(), save the data to variables and then use explode to process...
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