Some useful functions can be saved as source code, and you can avoid writing them again later.
File Read Function
// File Read Function
Function PHP_Read ($ file_name ){
$ Fd = fopen ($ file_name, r );
While ($ bufline = fgets ($ fd, 4096 )){
$ Buf. = $ bufline;
}
Fclose ($ fd );
Return $ buf;
}
?>
File Writing Function
// File Writing Function
Function PHP_Write ($ file_name, $ data, $ method = "w "){
$ Filenum = @ fopen ($ file_name, $ method );
Flock ($ filenum, LOCK_EX );
$ File_data = fwrite ($ filenum, $ data );
Fclose ($ filenum );
Return $ file_data;
}
?>
Static Page generation function
// Static page generation function
Function phptohtm ($ filefrom, $ fileto, $ u2u = 1 ){
If ($ u2u = 1 ){
$ Data = PHP_Read ($ filefrom );
} Else {
$ Data = $ filefrom;
}
PHP_Write ($ fileto, $ data );
Return true;
}
?>
Number of specified conditions
// Query the number of specified conditions
Function rec_exist ($ table, $ where ){
$ Query = "select count (*) as num from $ table". $ where;
$ Result = mysql_query ($ query) or die (nerror (1 ));
$ Rowcount = mysql_fetch_array ($ result );
$ Num = $ rowcount ["num"];
If ($ num = 0 ){
Return false;
}
Return $ num;
}
?>
Directory deletion function
// Directory deletion function
Function del_DIR ($ directory ){
$ Mydir = dir ($ directory );
While ($ file = $ mydir-> read ()){
If (is_dir ("$ directory/$ file") AND ($ file! = ".") AND ($ file! = "..")){