博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 文件操作
阅读量:4041 次
发布时间:2019-05-24

本文共 1696 字,大约阅读时间需要 5 分钟。

1. file ( string filename [, int use_include_path [, resource context]] )方法把整个文件读入一个数组中

<?php

// 将一个文件读入数组。本例中通过 HTTP 从 URL 中取得 HTML 源文件。
$lines = file ( 'http://www.example.com/' );
// 在数组中循环,显示 HTML 的源文件并加上行号。
foreach ( $lines as $line_num => $line ) {
    echo
"Line #<b> {
$line_num } </b> : " . htmlspecialchars ( $line ) . "<br />/n" ;
}
// 另一个例子将 web 页面读入字符串。参见 file_get_contents()。
$html = implode ( '' , file ( 'http://www.example.com/' ));
?>

注意: 返回的数组中每一行都包括了行结束符,因此如果不需要行结束符时还需要使用 函数。

 

2. file_get_contents -- 将整个文件读入一个字符串

 

3. string urlencode ( string str ) 编码 URL 字符串, ,

 

4. htmlspecialchars --  Convert special characters to HTML entities

    htmlspecialchars_decode --  Convert special HTML entities back to characters

<?php

$query_string = 'foo=' . urlencode ( $foo ) . '&bar=' . urlencode ( $bar );
echo
'<a href="mycgi?' . htmlentities ( $query_string ) . '">' ;
?>

 

5. file_exists -- 检查文件或目录是否存在

<?php

$filename = '/path/to/foo.txt' ;
if (
file_exists ( $filename )) {
    echo
"The file $filename exists" ;
} else {
    echo
"The file $filename does not exist" ;
}
?>

 

 

6.int file_put_contents ( string filename, string data [, int flags [, resource context]] )

和依次调用 , 以及 功能一样。

 

7.fileatime -- 取得文件的上次访问时间

<?php

// 输出类似:somefile.txt was last accessed: December 29 2002 22:16:23.
$filename = 'somefile.txt' ;
if (
file_exists ( $filename )) {
    echo
"$filename was last accessed: " . date ( "F d Y H:i:s." , fileatime ( $filename ));
}
?>

 

8. filectime -- 取得文件的 inode 修改时间

<?php

// 输出类似:somefile.txt was last changed: December 29 2002 22:16:23.
$filename = 'somefile.txt' ;
if (
file_exists ( $filename )) {
    echo
"$filename was last changed: " . date ( "F d Y H:i:s." , filectime ( $filename ));
}
?>

 

9.

转载地址:http://iyadi.baihongyu.com/

你可能感兴趣的文章
uboot start.s文件分析
查看>>
没有路由器的情况下,开发板,虚拟机Ubuntu,win10主机,三者也可以ping通
查看>>
本地服务方式搭建etcd集群
查看>>
安装k8s Master高可用集群
查看>>
忽略图片透明区域的事件(Flex)
查看>>
忽略图片透明区域的事件(Flex)
查看>>
AS3 Flex基础知识100条
查看>>
Flex动态获取flash资源库文件
查看>>
flex中设置Label标签文字的自动换行
查看>>
Flex 中的元数据标签
查看>>
flex4 中创建自定义弹出窗口
查看>>
01Java基础语法-13. if分支语句的灵活使用
查看>>
01Java基础语法-15.for循环结构
查看>>
01Java基础语法-16. while循环结构
查看>>
01Java基础语法-17. do..while循环结构
查看>>
01Java基础语法-18. 各种循环语句的区别和应用场景
查看>>
01Java基础语法-19. 循环跳转控制语句
查看>>
Django框架全面讲解 -- Form
查看>>
socket,accept函数解析
查看>>
今日互联网关注(写在清明节后):每天都有值得关注的大变化
查看>>