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

php中文网
发布: 2016-06-01 12:38:13
原创
1101人浏览过

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

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

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

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






// dtf.inc.php3

//

// DTF -- Delimited Text File Functions

// Written by: Goghs

// 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) {

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
$input[$i] = ereg_replace("|","|",$input[$i]);

}

}

return $input;

}





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

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

function dtf_remove_html_tag($input) {

if (is_string($input)) {

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

}

if (is_array($input)) {

for ($i=0; $i
$input[$i] = ereg_replace("
$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

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号