本文共 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/