首页 > 编程技术 > php

php实现多级分类筛选程序代码

发布时间:2016-11-25 17:20

现在这种多选择功能在很多网站都有,如现在很多电商网站都有N个条件选择了,下面小编为各位介绍一个简单的多级分类筛选实现方法。

主要注意这边有一个 $$这是变量的变量。 以后估计会常用这个做开发。

 代码如下 复制代码

<?php
 
$conditions = array('price','color','metal');//要进行筛选的字段放在这里
 
$price = $color = $metal='';//先给需要筛选的字段赋空值,这些值将输出到页面的hidden fileds 中
 
//以下循环给已经进行的筛选赋值,以便能够在下一次筛选中保留
 
foreach($conditions as $value){
 
    if(isset($_GET[$value])){
        $$value = $_GET[$value];
    }
 
}

 
//以下是演示输出$_GET数据
 
echo '<pre>';
 
print_r($_GET);
 
echo '</pre>';
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<title>分类筛选演示</title>
 
<style type="text/css">
 
body{font-size:14px;font-family:Tahoma,"宋体"}
 
</style>
 
<script type="text/javascript">
 
function Filter(a,b){
 
    var $ = function(e){return document.getElementById(e);}
 
    var ipts = $('filterForm').getElementsByTagName('input'),result=[];
 
    for(var i=0,l=ipts.length;i<l;i++){
 
        if(ipts[i].getAttribute('to')=='filter'){
 
           result.push(ipts[i]);
 
       }
 
    }
 
   if($(a)){
 
        $(a).value = b;
 
        for(var j=0,len=result.length;j<len;j++){
 
           if(result[j].value==''){
 
               result[j].parentNode.removeChild(result[j]);
 
           }
 
       }
 
        document.forms['filterForm'].submit();
 
    }
 
    return false;
 
}
 
</script>
 
</head>
 
<body>
 
<form id="filterForm" action="test.php" method="get">
 
<!--
 
form的id 要和程序里统一
 
为避免与其他使用的隐藏域冲突,添加了to属性
 
以下是筛选字段隐藏域
 
需要筛选的隐藏域需要加 to 属性
 
-->
 
<input to="filter" type="hidden" id="price" name="price" value="<?=$price?>" />
 
<input to="filter" type="hidden" id="color" name="color" value="<?=$color?>" />
 
<input to="filter" type="hidden" id="metal" name="metal" value="<?=$metal?>" />
 
</form>
 
<!--
 
要筛选的属性可以由程序生成,注意规律!
 
-->
 
价格:<a href="javascript:Filter('price','');">不限</a>

<a href="javascript:Filter('price','100-1000');">100-1000</a>
 
      <a href="javascript:Filter('price','1001-2000');">1001-2000</a>
 
     <a href="javascript:Filter('price','2001-3000');">2001-3000</a><br/>
 
颜色:<a href="javascript:Filter('color','红色');">红色</a>
 
      <a href="javascript:Filter('color','蓝色');">蓝色</a><br />
 
材质:<a href="javascript:Filter('metal','纯金');">纯金</a>
 
      <a href="javascript:Filter('metal','纯银');">纯银</a><br />
 
</body>
 
</html>

phpweb是一个企业建站系统了可以快速的实现企业群站创建了,但这款使用的编辑器并不是百度编辑器对于小编来讲是非常喜欢百度编辑器了,下面一起来看看phpweb更换百度编辑器的配置。

准备工作:

1.从UEditor 官网上面下载 最新版本的UEditor,现在最新版本为ueditor1_4_3-utf8-php,请下载php版本。

2.我们更换的是 news 模块下的编辑器,也就是新闻模块,请确保news/admin/下面,news_conadd.php,news_conmod.php,已经破解出源码,如果没有,请自行百度!

开始动手:

1.解压下载的压缩包直接到phpweb根目录

2.打开news_conadd.php文件夹

找到以下代码:

 代码如下 复制代码

<input type="hidden" name="body" value="<?php echo $body; ?>" />
<script type="text/javascript"" width=100% src="../../kedit/KindEditor.js"></script>
<script type="text/javascript">

var editor = new KindEditor("editor");
 editor.hiddenName = "body";
 editor.editorWidth = "680px";
 editor.editorHeight = "300px";
 editor.skinPath = "../../kedit/skins/default/";
 editor.uploadPath = "../../kedit/upload_cgi/upload.php";
 editor.imageAttachPath="news/pics/";
 editor.iconPath = "../../kedit/icons/";
 editor.show();
   function KindSubmit() {
editor.data();
 }

 </script>

然后直接注释掉,或者删除。

加入

 代码如下 复制代码
<script id="container" name="body" type="text/plain"></script>

然后在下面插入

 代码如下 复制代码
<!-- 配置文件 -->
<script type="text/javascript"" width=100% src="../../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript"" width=100% src="../../ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
var ue = UE.getEditor('container',{
   initialFrameWidth:"800",
   initialFrameHeight:"200"
  });
  
</script>

这样,新闻的添加就好了。

下面就是新闻的修改;

步骤和添加一样只是在实例化编辑器后面加入

 代码如下 复制代码

 <script type="text/javascript">
var ue = UE.getEditor('container',{
   initialFrameWidth:"800",
   initialFrameHeight:"200",
   
  });
  
  ue.ready(function() {
   //设置编辑器的内容
   ue.setContent('<?php echo htmlspecialchars_decode($body);?>');
   
   
  });
  
</script>

这样 修改就可以了。

注意:更换完成编辑器后,原来phpweb自带的分页就不能使用了

phpweb更换百度编辑器的配置教程

phpweb更换百度编辑器的配置教程

下面是修改新闻的时候:

phpweb更换百度编辑器的配置教程

写在最后:
百度UEditor 的上传图片路径是统一默认的,如果要修改,请打开 ueditor/php/config.json 下面进行修改。
以下是最近工作中总结的几个Drupal小问题,Drupal性能模块之简明分析对比,实现view动态输出的步骤方法,为Drupal主题添加主题内自带图片的正确方法。其中第一个是在网上找到的翻译国外内容,这此感谢这些默默翻译的高手。

Drupal性能模块的简明分析对比

原文:

Varnish

We explored various caching solutions available for Drupal. We shortlisted Varnish, Boost and Authcache modules. We performed a number of tests using these modules. We tested over 1000 pages from different locations. The average page load time without any caching was above 4.0 seconds. The average page load time with Drupal's default caching was 2.5 seconds. The average page load time with the Authcache module was reduced to 1.8 seconds. The average page load time with the Boost module was 1.7 seconds. The average page load time with Varnish module was 1.5 seconds. Therefore we preferred using the Varnish module. These stats are for this site only, the results may vary for other sites.

我简单翻译下:

用1000个不同的页面作的测试,

1.不用任何缓存模块:平均加载时间4秒以上;
2.使用drupal自带缓存:平均加载时间2.5秒;
3.使用Authcache模块,平均加载时间1.8秒;
4.使用Boost模块,平均加载时间1.7秒;
5.使用Varnish模块,平均加载时间1.5秒;

-----------------------------------------------

实现view动态输出的步骤方法

1、在 view 的属性页,选择 header
2、选择 Global: Text area
3、在弹出框里,覆写 输出
4、只有Replacement patterns 显示出来的字段,才能被调用
5、注意勾选 *Use replacement tokens from the first row

-----------------------------------------------

为Drupal主题添加主题内自带图片的正确方法

在为drupal的主题添加主题自带的一些图片的时候,会碰到一些路径问题,使用下面这些方法添加的图片,才能正确显示在页面上:

<img" width=100% src="<?php print $base_path . drupal_get_path('theme', 'yourtheme');?>/image/act-title.jpg">

在php标签里面输出url的时候要使用 $base_path 与 主题路径拼接出来的url 然后再加上主题目录里面的静态图片的路径,才能正确的显示.

验证URL有两种一种是利用正则表达式来验证URL是不是合适url规则了,另一个是利用函数来访问指定url看看是否可正常访问了,如果能正常访问自然就是合法的url地址了。

例子1

 代码如下 复制代码

<?php
function isValidUrl($url) {
 
    $patern = '/^http[s]?:\/\/'.
        '(([0-9]{1,3}\.){3}[0-9]{1,3}'.             // IP形式的URL- 199.194.52.184
        '|'.                                        // 允许IP和DOMAIN(域名)
        '([0-9a-z_!~*\'()-]+\.)*'.                  // 三级域验证- www.
        '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.'.     // 二级域验证
        '[a-z]{2,6})'.                              // 顶级域验证.com or .museum
        '(:[0-9]{1,4})?'.                           // 端口- :80
        '((\/\?)|'.                                 // 如果含有文件对文件部分进行校验
        '(\/[0-9a-zA-Z_!~\*\'\(\)\.;\?:@&=\+\$,%#-\/]*)?)$/';
 
    if(!preg_match($patern, $url)) {
        die( '您输入的URL格式有问题,请检查!');
    }
}

例子2

上面的例子只是验证url是不是正常的不代表是否可以访问了,我们可以使用如curl函数进行方法

 代码如下 复制代码

$url = "http://www.111cn.net ";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
$result = curl_exec($curl);
if ($result !== false)
{
  $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
  if ($statusCode == 404)
  {
    echo "URL Not Exists"
  }
  else
  {
     echo "URL Exists";
  }
}
else
{
  echo "URL not Exists";
}

除了这个函数还可以使用php的很多函数如 file、file_get_contents()、fopen函数来进行检测了。

Gravatar头像是现在博客通用的一个调用方法了,很多朋友的个人博客都使用了Gravatar头像了,但最近有很多站长发现Gravatar头像打开缓慢了,那么我们要如何解决Gravatar图片打不开或者打开慢的问题呢?下面来看看吧。

第一、如果我们还需要使用Gravatar头像

 代码如下 复制代码
function get_ssl_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img" width=100% src="https://secure.gravatar.com/avatar/$1?s=$2" class="avatar avatar-$2" height="$2" width="$2">',$avatar);
return $avatar;
}
add_filter('get_avatar', 'get_ssl_avatar');

在当前WORDPRESS主题中的FUNCTIONS.PHP页面中加入上面的代码,因为HTTP直接访问不了,这里调整为HTTPS的路径地址。
第二、使用本地头像

 代码如下 复制代码
function my_avatar($avatar) {
$tmp = strpos($avatar, 'http');
$g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
$tmp = strpos($g, 'avatar/') + 7;
$f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
$w = get_bloginfo('wpurl');
$e = ABSPATH .'avatar/'. $f .'.jpg';
$t = 1209600;
if ( !is_file($e) || (time() - filemtime($e)) > $t ) {
copy(htmlspecialchars_decode($g), $e);
} else $avatar = strtr($avatar, array($g => $w.'/avatar/'.$f.'.jpg'));
if (filesize($e) < 500) copy($w.'/avatar/default.jpg', $e);
return $avatar;
}
add_filter('get_avatar', 'my_avatar');

同样的,在FUNCTIONS.PHP文件中,加入上面的代码,把头像缓存本地,同样的使用avatar文件夹作为根目录,可以先放入一个default.jpg作为默认不存在的头像展示图片。
第三、使用第三方评论插件
使用第三方评论插件可以展示头像的,目前不存在调用问题,之前老左也写过一篇"点评四款社会化评论系统",目前使用较多的还是多说和畅言,前者用户体验还可以,就是服务器宕机不稳定。后者基于搜狐提供的,界面一般,但服务器是比较稳定的。

标签:[!--infotagslink--]

您可能感兴趣的文章: