//fopen 读取文件实例
代码如下 | 复制代码 |
$path ='a.txt'; |
//file_get_contents读取文件
代码如下 | 复制代码 |
if( file_exists( $path ) ) //file |
读取文本文件
代码如下 | 复制代码 |
$cbody = file($path); |
print_r($cbody); //因为file读取出来的文件是以数组形式保存的,所以用print_r输出。
代码如下 | 复制代码 |
function pagenavi($total, $offset){ global $conf_pagemax; global $conf_home; global $conf_pastlog; global $view; $next = $offset + $conf_pagemax; $prev = $offset - $conf_pagemax; echo " <!-- page navigation --> "; if($offset > $conf_pagemax-1){ echo "<a href="index.php?offset=$prev"; if($view == "past"){ echo "&view=past"; } echo ""><<上一页</a> "; } ($total % $pagemax)? $pagenum = ($total/$conf_pagemax) + 1: $pagenum = ($total/$conf_pagemax); if($total <= $conf_pagemax) $pagenum = 0; $c = 0; $page = 1; if($total > $conf_pagemax){ echo "[<b> "; while($pagenum > 0){ if($offset == $c){ $str .= " $page "; } else { $str .= " <a href="index.php?offset=$c"; if($view =="past"){ $str .= "&view=past"; } $str .= "">$page</a> "; } $page++; $pagenum--; $c = $c + $conf_pagemax; } echo "$str </b>] "; } if($next < $total){ echo "<a href="index.php?offset=$next"; if ($view == "past"){ echo "&view=past"; } echo "">下一页>></a> "; } echo "</td></tr></table>"; echo " <!-- end of page navigation --> <br><br>"; echo " [ <a href="$conf_home">返回主页</a> ] "; if($view != "past"){ if(file($conf_pastlog)){ echo "[ <a href="index.php?view=past">以前的留言</a> ]"; } } echo " [ <a href="search.php"> 搜索</a> ] "; echo " [ <a href="index.php">留言板首页</a> ] "; } |
代码如下 | 复制代码 |
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <body> /*测试 这里是www.111cn.net为你提供一款正则取处文章内容中的图片地址代码如下 [1] => array [2] => array [3] => array [4] => array ) |
代码如下 | 复制代码 |
$uid = $_request['uid']; checkusername($uid); function checkusername() { $title = $uid; if( empty( $title ) ) { return false; } else { mysql教程_connect('localhost','root','root'); mysql_select_db('test'); mysql_query("set names 'gb2312'"); $sql = "select * from cn_user where username ='$title'"; $row = mysql_query($sql); if( mysql_num_rows( $row ) ) { echo '用户名己经存'; } else { return '可以注册'; } } } |
/*
create table `test`.`cn_user` (
`id` int not null auto_increment ,
`username` varchar( 20 ) not null ,
`times` date null ,
primary key ( `id` )
) engine = myisam
插入数据
insert into `test`.`cn_user` (
`id` ,
`username` ,
`times`
)
values (
null , 'jimmy', null
), (
null , 'www.111cn.net', null
);
*/
这是一款删除文件夹的php函数,本函数用的是递归删除,他可以删除指定目录的所有文件夹与文件,可以删除不是空目录的文件夹,方便的很,下面来看看函数实例方法。代码如下 | 复制代码 |
/*—————————————————— */ //– 递归删除文件及目录 //– 例: del_dir ('../www.1111cn.net/');注意:返回的/是必须的 //– $type 强制删除目录, true 是 ,false 否 /*—————————————————— */ function del_dir ($dir,$type=true) { $n=0; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //.svn 忽略 svn 版本控制信息 if ( $file == '.' or $file =='..' or $file == '.svn') { continue; } if (is_file ($dir.$file)) { unlink($dir.$file); $n++; } if (is_dir ($dir.$file)) { del_dir ($dir.$file.'/'); if ($type) { $n++; rmdir($dir.$file.'/'); } } } } closedir($dh); } return $n; } |
很容易看懂吧。原理很简单,首先是查询目录所有文件或目录,如果是文件就删除了,如果是目录看看是不是空目录,如果是的删除,否则再调用本函数一次类推,就实例了删除不是空目录的功能了。