php常用函数2
文件读取函式
//文件读取函式
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!="..")){
del_DIR("$directory/$file");
}else{
if(($file!=".") AND ($file!="..")){
unlink("$directory/$file");
//echo "unlink $directory/$file ok ";
}
相关文档:
Guoqzhang_PHP 简易php framework 请多指点。
Guoqzhang_PHP V 1.0 的PHP开发框架,采用MVC设计模式,运用Smarty模板引擎术和MySQL数据库技术开发而成。
设计到开发完成耗时20个工作日左右,时间短,可能存在一些bug,请大家指正.作者mail:guoqzhang@gmail.com
url:http://download.csdn ......
<?php
date_default_timezone_set("Etc/GMT-8");
header("content-type:text/html; charset=utf-8");
/**
* 自己定义的一个生成日历的类
* @author 张伟灿<yuanfen860913@163.com>
* @version 1.0.0
*
*/
class myCalendar
{
......
一、PHP函数Date()获取当前时间
代码:
<?php echo $showtime=date("Y-m-d H:i:s");?>
显示的格式: 年-月-日 小时:分钟:秒
相关参数:
a:"am"或者"pm"
A:"AM"或者"PM"
d:几日,二位数字,若不足二位则前面补零,如: "01"至"31"
D:星期几,三个英文字母,如: "Fri"
F:月份,英文全名,如: "Jan ......
php中substr的用法详解
php.net中关于substr的说明很简单:
start
If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so for ......
in_array(value,array,type)
in_array 作用是用于查看 value 是否在 array 中存在,如果参数 value 是字符串,且 type 参数设置为 true,则搜索区分大小写。则 in_array 是 区分大小写 的。
有一点需要注意,当 array 中包含 value 的值,则返回 true; 但是,如果两者参数之间相等,则返回 false
例如:
$str = 'a';
......