I can't afford to rent MySQL support, so I can only use flat file storage. I use common perl | bounded format, such as name | email | homepage. I wrote a few functions and thought it was a little useful. What do you have and want to tell me? I want to improve it .? Php // dtf. inc. php3 // DT because I cannot afford MySQL support, I can only use flat file storage,
I use the "|" format commonly used by perl, such as "name | email | homepage.
I wrote a few functions and thought it was a little useful. What do you have,
I also hope to tell you how to perfect it.
// 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;
}
// This function is useless. you can use htmlspecialchars.
// However, it is useful if you only need to process "<", ">" and do not need to process quotation marks and &
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
$ Input [$ I] = ereg_replace ("<", "<", $ input [$ I]);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service