php无限级分类程序

 更新时间:2016年11月25日 15:50  点击:1550
这里利用数组来做实例哦,有需要的要改成数据库查询然后再存到数据操作,有需要参考一下。
 代码如下 复制代码

<?php

$a = array(
  'AAAAAA'  =>  array(
        'aaaaaa' => array(
                 '111111',
                 '222222',
                 '333333'
        ),
        'bbbbbb'  => array(
                  '111111',
                 '222222',
                 '333333'
        ),
        'cccccc'  => array(
                  '111111',
                  '222222',
                  '333333'
        ),                     
  ),
  'BBBBBB'  =>   array(
        'aaaaaa' => array(
                  '111111',
                  '222222',
                  '333333'
        ),
        'bbbbbb'=> array(
                  '111111',
                  '222222',
                  '333333'
        ),
        'cccccc'=> array(
                  '111111',
                  '222222',
                  '333333'
        ),
  ),
  'CCCCCC'  => array(
        'aaaaaa'=> array(
                  '111111',
                  '222222',
                  '333333'
        ),
        'bbbbbb'=> array(
                  '111111',
                  '222222',
                  '333333'
        ),
        'cccccc'         => array(
                  '111111',
                  '222222',
                  '333333'
        ),
  ),
);

foreach ($a as $k=>$v){
   echo $k."<br>";
  // if(is_array($v)){
       foreach($v as $key=>$val){
          echo "  ".$key."<br>";
  //     }                           
       if(is_array($val)){
          foreach($val as $kkk=>$vall){
             echo "    ".$vall."<br>";
          }
       }
   }
   echo "<br>";
   }
  
  
    /*******mysql查询无限级分类的代码******/
    /***
   $sql = "SELECT a.Title AS big, b.Title AS small
            FROM largeTitle AS a LEFT JOIN smallTitle  AS b ON  a.ID=b.LargeID";
           
    $a = array();
   
    $r = mysql_query($sql);
   
    while( $arr = mysql_fetch_array($r)){
        $a[$arr['big']] = $arr['small'];
    }
    ***/
?>           

php 删除文件与目录代码是对文件与目录管理时会常用到了, 其实我们是删除文件后再删除目录的,因为php不能直接删除不是null的文件夹.
 代码如下 复制代码

function RmDirFiles($indir)
 {
    $dh = dir($indir);
    while($filename = $dh->read()) {
      if($filename == "." || $filename == "..")
       continue;
      else if(is_file("$indir/$filename"))
       @unlink("$indir/$filename");
      else
        $this->RmDirFiles("$indir/$filename");
    }
    $dh->close();
    @rmdir($indir);
 }


 //获得某目录合符规则的文件
 

 代码如下 复制代码
function GetMatchFiles($indir,$fileexp,&$filearr)
 {
    $dh = dir($indir);
    while($filename = $dh->read())
    {
      $truefile = $indir.'/'.$filename;
      if($filename == "." || $filename == ".."){
       continue;
      }
      else if(is_dir($truefile)){
       $this->GetMatchFiles($truefile,$fileexp,$filearr);
      }
      else if(preg_match("/.(".$fileexp.")/i",$filename)){
       $filearr[] = $truefile;
      }
    }
    $dh->close();
 }


 //删除文件

 代码如下 复制代码
 function DeleteFile($filename)
 {
  $filename = $this->baseDir.$this->activeDir."/$filename";
  if(is_file($filename)){ @unlink($filename); $t="文件"; }
  else{
   $t = "目录";
   if($this->allowDeleteDir==1) $this->RmDirFiles($filename);
  }
  ShowMsg("成功删除一个".$t."!","file_manage_main.php?activepath=".$this->activeDir);
  return 0;
 }

 

提供一个常见的php下载css中图片代码,有需要的朋友可以下载,只要把$url填写好就行了哈。
 代码如下 复制代码

<?php教程
$url = 'http://www.111cn.net';
$data = file_get_contents('abc.css教程');
preg_match('/(.*//.*?)//',$url,$host);
$host = $host[1];
if (!is_dir('img')) { mkdir('img'); }
$regex = '/url('{0,1}"{0,1}(.*?)'{0,1}"{0,1})/';
preg_match_all($regex,$data,$result);
foreach ($result[1] as $val) {
if (preg_match('/^http.*/',$val)) { $target = $val; }
else if (preg_match('/^/.*/',$val)) { $target=$host.$val; }
else { $target=$url.$val; }
echo $target."<br/>rn";
preg_match('/.*/(.*.D+)$/',$val,$name);
if (!is_file('./img/'.$name[1])) {
copy($target,'./img/'.$name[1]);
}
}?>

一款由网页提供的php mysql 分页显示代码,样式比较多有需要的朋友可以下载使用。

先我们来看看分页的效果,如果是你想要的就可以下载了。

p.php教程分页类的核心代码

 代码如下 复制代码

<?php
/*

php 分页类
只要实现分页。不与数据库教程连接。

如果是伪静态 只需修改84行以下的A标签即可 如   "<a href='index_".$i.".html'>".$i."</a>"  (index_表示你的伪静态地址) 其他的A标签页是一样

*/

/*

          鄙人工作时间写了个简单实用的  php 分页类   现和大家分享。。
   
    QQ:348145486
   
    email:  tzk_php@163.com 
   
    欢迎大家一起学习交流

*/


class Page{

 public $page_size="20";                     //每页显示的数据数目
 public $page_num;                           //总的数据数目
 public $page_url="";                        //分页的当前URL
 public $pageval;                            //分页的当前页
 public $page_ys;                            //总的页数
 public $page_tf=false;                      //判断能否执行分页的值
 public $page;

 /**********初始化分页类************/
   
 function __construct($page_num,$page_size=""){
  $this->page_num=$page_num;                                                            //获取所有需要显示的数据数目

  if($page_size!=""){
   $this->page_size=$page_size;                                                      //获取每页显示数据数据
  }

  $this->page_url=$_SERVER['SCRIPT_NAME'];                                              //获取当前的URL地址

  if($this->page_num>$this->page_size){                                                 //判断是否能执行分页
   $this->page_ys=ceil($this->page_num/$this->page_size);                            //获取总的分页数
   $this->page_tf=true;                                                              //将分页权限复制以便下面再次判断
  }

  if(!empty($_GET['page'])){                                                            //只允许页码在分页数范围内
   if($_GET['page']>="1"){
    if($_GET['page']<=$this->page_ys){
     $this->pageval=$_GET['page'];
    }else{
     $this->pageval=$this->page_ys;
    }
   }else{
    $this->pageval="1";
   }
  }else{
   $this->pageval="1";
  }

  $this->page=($this->pageval-1)*$this->page_size;                                       //查询数据库数据时的第一条数据

 }

 /************执行分页 返回分页按钮**********/


 function page_fy($val=""){
  if($this->page_tf==true){
   if($val==""){
    return $this->page_style_one();
   }else if ($val=="1"){
     return $this->page_style_two();
   }elseif ($val=="2"){
    return $this->page_style_three();
   }
  }
 }

 /**********分页按钮 样式一*********/

 function page_style_one(){
  if($this->pageval=="1"){
   $up="1";
  }else{
   $up=$this->pageval-1;
  }

  if($this->pageval>=$this->page_ys){
   $down=$this->page_ys;
  }else{
   $down=$this->pageval+1;
  }
  $one="<a href='".$this->page_url."?page=1'>首页</a>";
  $two="<a href='".$this->page_url."?page=".$up."'>上一页</a>";
  $three="<a href='".$this->page_url."?page=".$down."'>下一页</a>";
  $four="<a href='".$this->page_url."?page=".$this->page_ys."'>末页</a>";
  return $page_echo = $one.$two.$three.$four;
 }

 /***********分页按钮 样式二*************/

 function page_style_two(){                                                 //下面这个呢,逻辑很复杂,思维很林乱,
  $page_echo="";
  if($this->pageval=="1"){
   $up="1";
  }else{
   $up=$this->pageval-1;
  }

  if($this->pageval>=$this->page_ys){
   $down=$this->page_ys;
  }else{
   $down=$this->pageval+1;
  }
  $two="<a href='".$this->page_url."?page=".$up."'>上一页</a>";
  $three="<a href='".$this->page_url."?page=".$down."'>下一页</a>";
  
  if($this->page_ys>"6"){

      if($this->pageval<=3){
       $i=2;
       $i_to=5;       
      }elseif ($this->pageval>=($this->page_ys-2)){
       $i=$this->page_ys-4;
       $i_to=$this->page_ys-1;
      }else{
       $i=$this->pageval-2;
       $i_to=$this->pageval+2;
      }
     
  if($this->pageval>4){
   $page_one="...";
  }else{
   $page_one="";
   }

  if($this->pageval<($this->page_ys-3)){
   $page_two="...";
  }else{
   $page_two="";
   }
 
  for ($i;$i<=$i_to;$i++){
   $page_echo.="<a href='".$this->page_url."?page=".$i."'>".$i."</a>";                //如果是伪静态 只需修改A标签即可 如   "<a href='index_".$i.".html'>".$i."</a>"   其他的A标签页是一样
  }   
 
  }else{
   for ($i=2;$i<=($this->page_ys-1);$i++){
       $page_echo.="<a href='".$this->page_url."?page=".$i."'>".$i."</a>";
      }
     
  }
  
  return $two."<a href='".$this->page_url."?page=1'>1</a>".$page_one.$page_echo.$page_two."<a href='".$this->page_url."?page=".$this->page_ys."'>".$this->page_ys."</a>".$three;

 }
 
 /*****************分页按钮 样式三  样式3大家可以写了。 *******************/
 
 function page_style_three(){
  return $this->page_style_two();
 }

 

}
?>

调用方法

 代码如下 复制代码

<style type="text/css教程">

a{ color:#fff; text-decoration:none; padding:2px 5px; background-color:#09C; border:#F63 double 1px; margin:0 2px; font-size:14px;}
a:hover{color:#f00; background-color:#CCC;}
body{color:#999;}
</style>
<?php

include 'p.php';                    //载入分页类库
         
$page=new Page('12345',"10");               //实例化类库     312  为显示的总条数     10   为每页显示的条数  


echo "样式二<br/>";
echo "<br/>";
echo "<br/>";
echo $page->page_fy('1');                //使用分页样式

echo "<br/>";echo "<br/>";echo "<br/>";echo "<br/>";


echo "样式一<br/>";
echo "<br/>";
echo "<br/>";
echo $page->page_fy();                    //使用分页样式


?>

这里提供一款常用的标准的php验证码生成程序有需要的朋友可以参考一下
 代码如下 复制代码

<?php教程

session_start();

$enablegd = 1;
//判断图像处理函数是否存在
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellips教程e','imagepng');
foreach($funcs as $func)
{
 if(!function_exists($func))
 {
  $enablegd = 0;
  break;
 }
}

ob_clean(); //清理缓冲

if($enablegd)
{
 //create captcha
 $consts = 'cdfgkmnpqrstwxyz23456';
 $vowels = 'aek23456789';
 for ($x = 0; $x < 6; $x++)
 {
  $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1); //获取$consts中的一个随机数
  $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1); //获取$vowels中的一个随机数
 }
 $radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
 $_SESSION['checkcode'] = $string = substr($radomstring,0,4); //显示4个字符

 $imageX = strlen($radomstring)*8; //图像的宽
 $imageY = 20;      //图像的高
 $im = imagecreatetruecolor($imageX,$imageY); //新建一个真彩色图像

 //creates two variables to store color
 $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250)); //背景色
 $foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
  imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
  imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
  imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255))
 );
 $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80); //分配颜色并说明透明度
 $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160)); //中间背景
 $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //中间背景2

 //与左上角的颜色相同的都会被填充
 imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
 //往图像上写入文字
 imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], 'C:WindowsFontsArial.ttf', $string[0]);
 imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], 'C:WindowsFontsArial.ttf', $string[1]);
 imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)],'C:WindowsFontsArial.ttf', $string[2]);
 imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)],'C:WindowsFontsArial.ttf', $string[3]);

 //画边框
 $border = imagecolorallocate($im, 133, 153, 193);
 imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);

 //画一些随机出现的点
 $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
 for ($i=0;$i<80;$i++)
 {
  imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
 }
 //画随机出现的线
 for ($x=0; $x<9;$x++)
 {
  if(mt_rand(0,$x)%2==0)
  {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999)); //画线
   imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2); //画椭圆
  }
  else
  {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
   imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
  }
 }
 //output to browser
 header("content-type:image/pngrn");
 imagepng($im);
 imagedestroy($im);
}
else
{
 $files = glob(XINCHENG_ROOT.'images/checkcode/*.jpg');
 if(!is_array($files)) die('请检查文件目录完整性:/images/checkcode/');

 $checkcodefile = $files[rand(0, count($files)-1)]; //随机其中一个文件
 $_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); //获得文件名

 header("content-type:image/jpegrn");
 include $checkcodefile;
}
?>

[!--infotagslink--]

相关文章

  • C#开发Windows窗体应用程序的简单操作步骤

    这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
  • C++调用C#的DLL程序实现方法

    本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
  • 微信小程序 页面传值详解

    这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
  • C#使用Process类调用外部exe程序

    本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • 使用GruntJS构建Web程序之构建篇

    大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
  • 微信小程序二维码生成工具 weapp-qrcode详解

    这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
  • uniapp微信小程序:key失效的解决方法

    这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
  • 将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文

    时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25
  • PHP实现无限级分类(不使用递归)

    无限级分类在开发中经常使用,例如:部门结构、文章分类。无限级分类的难点在于“输出”和“查询”,例如 将文章分类输出为<ul>列表形式; 查找分类A下面所有分类包含的文章。1.实现原理 几种常见的实现方法,各有利弊。其中...2015-10-23
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • 微信小程序 网络请求(GET请求)详解

    这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
  • 微信小程序自定义tabbar组件

    这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
  • PHP实现递归无限级分类

    在一些复杂的系统中,要求对信息栏目进行无限级的分类,以增强系统的灵活性。那么PHP是如何实现无限级分类的呢?我们在本文中使用递归算法并结合mysql数据表实现无限级分类。 递归,简单的说就是一段程序代码的重复调用,当把...2015-10-23
  • 微信小程序如何获取图片宽度与高度

    这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
  • ecshop商品无限级分类代码

    ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25
  • 微信小程序实现点击导航条切换页面

    这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19
  • 微信小程序手势操作之单触摸点与多触摸点

    这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13
  • 微信小程序实现canvas分享朋友圈海报

    这篇文章主要为大家详细介绍了微信小程序实现canvas分享朋友圈海报,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-21
  • 微信小程序(应用号)开发新闻客户端实例

    这篇文章主要介绍了微信小程序(应用号)开发新闻客户端实例的相关资料,需要的朋友可以参考下...2016-10-25