教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 file_get_contents() 与file的区别

file_get_contents() 与file的区别

发布时间:2019-04-04   编辑:jiaochengji.com
教程集为您提供file,get,contents() 与file的区别等资源,欢迎您收藏本站,我们将为您提供最新的file,get,contents() 与file的区别资源

以前没注意可以使用file这个函数了,今天在做一个php把txt文本数据入导到数据库开始我是用file_get_contents(),把数据保存到变量再用explode处理,但后来在网上找到到关于file函数的用法,确实觉得file函数确实漂亮,好使用,下面我们来看看

好了下面我们来看个例子吧.先看file_get_contents()函数吧,我现在要把文本文件a.txt的内容保存到一个数据下面是a.txt的内容如下.

aaaaaa

bbbbbb

bbbbccc

好了,就这三行,现在看file_get_contents的操作方法.

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

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

也不多只有三行就完成了,那么我们来看看file函数吧.

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

就完成了,效果与上面完全相同的.

呵呵,其实php有很多函数是我们常常没被用到,我们也不需要记得他,只要知道有这个东东就行了,

好最后申明一下:本站原创文章转载请注明:  www.111cn.net/phper/php.html

您可能感兴趣的文章:
file_get_contents() 与file的区别
PHP fopen/file_get_contents与curl性能比较
php中curl、fsocket、file_get_content函数比较
php explode 与 implode用法与区别
有关php的ob_flush()与flush()使用方法
PHP CURL或file_get_contents获取网页标题的代码
shell判断文件是否存在的方法
php获取网页标题的三种方法示例
php去掉bom头的代码分享
php 遍历目录文件编码转换

[关闭]
~ ~