下一篇 » « 上一篇

文本文件数据库处理函数库

作者:爱好者    时间:2008-01-22    来源:php之家    点击:4470    本文共1篇文章 字体:[ ]

文本文件数据库处理函数库

因为我租不起MySQL支持 所以只能采用扁平文件存储

我是采用perl常用的
"|"定界的格式就像 "name|email|homepage" 这样的格式。

随便写了几个函数
觉得还是有点用处的。 大家有什么心得

也希望能告诉我啊
我来完善完善。



<?php



// dtf.inc.php3

//

// DTF -- Delimited Text File Functions

// Written by: Goghs <goghs@mail.com>

www.444p.com php学习之家



// http://www.eqiao.com

//

// Function to manage a delimited text file database



function dtf_fetch_all_as_string($filename) {

$fp = fopen( $filename, "r" );

$current = fread($fp, filesize($filename));

fclose($fp);

return $current;

}





function dtf_fetch_all_as_array($dbname) {

return file($dbname);

}



function dtf_update_db($dbname, $item) {

if (file_exists($dbname)):

$fp = fopen($dbname,"w+");

fputs($fp,$item);

fclose($fp);

else:

$fp = fopen($dbname,"w");

fputs($fp,$item);

fclose($fp);

endif;

}



function dtf_get_total_rows($dbname) {

return count(file($dbname));

}



function dtf_remove_pipe($input) {

www.444p.com php学习之家



if (is_string($input)) {

// $input=ereg_replace("|","",$input); // It’s said that str-replace is faster than ereg_replace

$input=str_replace("|","",$input);

}

if (is_array($input)) {

for ($i=0; $i<count($input); $i++) {

$input[$i] = ereg_replace("|","|",$input[$i]);

}

}

return $input;

}





// 这个函数没有用, 用htmlspecialchars就可以

// 但是如果只需要处理"<",">"而不需要处理 引号和 &时就很有用

function dtf_remove_html_tag($input) {

if (is_string($input)) {

$input = ereg_replace("<","<",$input);

$input = ereg_replace(">",">",$input);

}

if (is_array($input)) {

for ($i=0; $i<count($input); $i++) { php学习之家

$input[$i] = ereg_replace("<","<",$input[$i]);

$input[$i] = ereg_replace(">",">",$input[$i]);

}

}

return $input;

}





// 可以定制这个函数, 控制是否允许html标记等

function dtf_sanitize($input) {

$input = dtf_remove_pipe($input);

// $input = dtf_remove_html_tag($input);

$input = stripslashes($input);

$input = htmlspecialchars($input);

return $input;

}



?&g
发表评论
密码: (游客不需要密码)
记住我【Alt+S 或 Ctrl+Enter 快速提交】

搜索工具


热门搜索: [html][html][else][MYsql][mysql][调用][date][print][配置][配置]