Useful php function _ PHP Tutorial

Source: Internet
Author: User
Useful php functions. Some useful functions can be saved as source code, and you can avoid writing them again later. File read function functionPHP_Read ($ file_name) {$ fdfopen ($ file_na is a useful function. you can save it as the source code and avoid writing it 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! = "..")){

Bytes. File read function // function PHP_Read ($ file_name) {$ fd = fopen ($ file_na...

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.