易截截图软件、单文件、免安装、纯绿色、仅160KB

几个 PHP 文件读写函数和 CSVFileObject 类

/**
* 打开关闭文件
*/
fopen() // 2/4: 2 个必选参数, 4 个参数;
fclose() // 1/1;
/**
* 读取文件
*/
// 需先用 fopen() 打开文件才能读取的函数;从文件指针处开始读取
fgetc() // 1/1; 读取一个字符
fgets() // 1/2; 读取一行
fgetss() // 1/3; 读取一行并去除 HMTL 标签
fgetcsv() // 1/5; 读取一行并解析为 csv 字段,返回数组
fread() // 2/2; 读取指定字节的字符
fscanf() // 2/n; 从文件中格式化输入
// 不需要先 fopen() 打开文件的函数
file() // 1/3; 读取整个文件内容到一个数组,文件中一行对应数组中一个元素
file_get_contents() // 1/5; 读取整个文件到一个字符串
readfile() // 1/3; 读入一个文件并写入到输出缓冲。
/**
* 写入文件
*/
fwrite() / fputs() // 2/3; 写入文件(可安全用于二进制文件), 需先 fopen()
fputcvs() // 2/4; 将行格式化为 CSV 并写入文件指针,需先 fopen()
file_put_contents() // 2/4; 将字符串整个写入文件
/**
* 文件指针
*/
ftell() // 1/1; 返回文件指针读/写的位置
fseek() // 2/3; 在文件指针中定位
rewind() // 1/1; 倒回文件指针的位置
/**
* 使用 SplFileObject 方法 fgetcsv() 时最后一行后面还会解析出一个数组
* eg:
* $it = new SplFileObject('sample.csv');
* while( $arr = $it->fgetcsv() ){
* print_r( $arr)
* }
*/
class CSVFileObjectException extends Exception{
//
}
class CSVFileObject extends SplFileInfo implements Iterator{
protected $current_line;
protected $map;
protected $column_cnt;
protected $fp;
function __construct( $filename, $mode, $use_include_path = FALSE, $context = NULL)
{
$this->ensure( ! is_readable( $filename), "CSV file {$filename} does not exists or is not readable");
if( is_null( $context)){
$this->fp = @fopen( $filename, $mode, $use_include_path);
}else{
$this->fp = @fopen( $filename, $mode, $use_include_path, $context);
}
$this->ensure( ! $this->fp, "open CSV file {$filename} failure");
parent::__construct( $filename);
$this->current_line = 0;
$


相关文档:

超级简单的php+mysql留言本源码

 共3个文件
IncDB.php数据库连接
index.php首页
InsetToDB.php数据库操作
数据库lguestbook里面建表
CREATE TABLE `intd` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set utf8 collate utf8_bin N ......

PHP header() examples

 //用这个header指令来解决URL重写产生的404 header     
header('HTTP/1.1 200 OK');     
   
// 页面没找到     
header('HTTP/1.1 404 Not Found');     ......

PHP码农进化史4


1.echo();2.print();3.die();4.printf();5.sprintf();6.print_r;7.var_dump();
1.echo()
输出多个字符串,可以多个参数,不需要圆括号,无返回值。
2.print()
只能输出一样东西,需要圆括号,有返回值,执行失败是返回flase.
3.die()
输出内容,停止程序。*多用于数据库的链接时,检验是否出错。
4.printf()
prin ......

php面向对象


1.类和对象。
类是一类事物的描述。抽象,概念上的定义。
对象是实际存在的每个个体。也叫实例。对象是new出来的。$p = new Person();
2.属性
用来描述类中的数据元素。(也叫数据/状态)
修饰符(PHP5中必须修饰):public(公开,类的内外部读取修改),private(私有只在当前类中读取修改),protected(保护,能在这个类和 ......

php调用mysql存储过程返回多个结果集的处理

 返回一个结果全世界都知道怎么处理,关键是返回多个结果集就不好办了,下面有一解决办法
存储过程代码
DELIMITER $$;
DROP PROCEDURE IF EXISTS `test`.`sp_test`$$
CREATE PROCEDURE `test`.`sp_test` ()
BEGIN
    select * from `user`.`user` limit 0, 50;
    select coun ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号