php专区

 首页 > php专区 > PHP应用 > php函数大全 > 很有用的php函数

很有用的php函数

分享到:
【字体:
导读:
          很有用的一些函数,你可以作为源码保存,然后以后避免重复编写。文件读取函式 文件读取函式 function PHP_Read($file_name) { $fd=fopen($file_name,r); while($bufline=fgets($fd, 4096)){ $b

  很有用的一些函数,你可以作为源码保存,然后以后避免重复编写。
文件读取函式
   //文件读取函式
   function PHP_Read($file_name) {
   $fd=fopen($file_name,r);
   while($bufline=fgets($fd, 4096)){
   $buf.=$bufline;
    }
   fclose($fd);
   return $buf;
    }
   ?>
文件写入函式
      //文件写入函式
   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;
    }
   ?>
静态页面生成函式
   //静态页面生成函式
   function phptohtm($filefrom,$fileto,$u2u=1){
   if($u2u==1){
   $data=PHP_Read($filefrom);
    }else{
   $data=$filefrom;
    }
   PHP_Write($fileto,$data);
   return true;
    }
   ?>
指定条件信息数量检索函式
      //指定条件信息数量检索函式
   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;
    }
   ?>
目录删除函式
   //目录删除函式
   function del_DIR($directory){
   $mydir=dir($directory);
   while($file=$mydir->read()){
   if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
分享到:
PHP 和 XML: 使用expat函数(二)
  PHP 和 XML: 使用expat函数(二)   让我们看一下实际处理这个文档的PHP代码。 /*NewsBoy : News system for the web written in PHP by Justin Grant (Web: jusgrant.cjb.net or justin.host.za.net Mail: justin@glendale.net)25 March V0.0.2 Converted Newsboy to a PHP class, allowing the layout to be easily...
简单的页面缓冲技术(三)
  ontent.php3文件用来处理动态页面。用户可以通过content.php3?page=id号来读出一个数据文件。具体方法我就不说了,大家只要知道每个数据文件都有一个不同的id号,这样content.php3?page=id号的方式就可以唯一标识一个数据文件。 第1-3行,生成临时文件名。将'?','&'等字符替换成'_'。 ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……