Home >Backend Development >PHP Tutorial >Very useful php functions_PHP tutorial

Very useful php functions_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:35911browse

​ There are some very useful functions that you can save as source code to avoid having to write them again in the future.
File reading function
//File reading 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;
}
?>
Specify condition information quantity retrieval function
//Retrieval function for specifying the quantity of conditional information
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!="..")){

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445596.htmlTechArticleThere are some very useful functions that you can save as source code and avoid duplication in the future. File reading function //File reading function function PHP_Read($file_name) { $fd=fopen($file_na...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn