Useful PHP Functions _php tutorials

Source: Internet
Author: User
Some useful functions, you can save as source code, and then avoid repeating writing.
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-Write function
File-Write 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-generating functions
Static page-generating functions
function phptohtm ($filefrom, $fileto, $u 2u=1) {
if ($u 2u==1) {
$data =php_read ($filefrom);
}else{
$data = $filefrom;
}
Php_write ($fileto, $data);
return true;
}
?>
Specifying the number of conditional information retrieval functions
Specifying the number of conditional information retrieval functions
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 Delete function
Directory Delete function
function Del_dir ($directory) {
$mydir =dir ($directory);
while ($file = $mydir->read ()) {
if (Is_dir ("$directory/$file") and ($file! = ".") and ($file! = "...")) {

http://www.bkjia.com/PHPjc/445596.html www.bkjia.com true http://www.bkjia.com/PHPjc/445596.html techarticle Some useful functions, you can save as source code, and then avoid repeating writing. File read function//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.