Emlog实现最新头条文章标题加摘要显示代码 emlog

最新置顶头条文章标题加摘要显示的效果,把以下代码复制到module.php里面,如需调用分类置顶文章请把top='y'改为sortop='y'即可


<?php
//首页置顶头条,不带图片
function sheli_zdLog() {
$db = MySql::getInstance();
$sql = "SELECT gid,title,content,date FROM ".DB_PREFIX."blog WHERE type='blog' and top='y' ORDER BY `top` DESC ,`date` DESC LIMIT 0,1";
$list = $db->query($sql);
while($row = $db->fetch_array($list)){
//$row['content'] = htmlspecialchars($row['content']);
$row['content'] = strip_tags($row['content']);?>
<h1><a href="<?php echo Url::log($row['gid']); ?>" title="<?php echo $row['title']; ?>" target="_blank"><?php echo $row['title']; ?></a></h1>
<span class="note"><?php echo mb_substr($row['content'],0,85,'utf-8'); ?>...</span><a href="<?php echo Url::log($row['gid']); ?>" target="_blank">阅读全文>></a>    
<?php } ?>
<?php } ?>



如果需要带图片请使用下面代码放入module.php中,如需调用首页置顶文章请把sortop='y'改为top='y'即可



<?php //分类置顶头条,带图片
function sheli_zdLog(){ $db = MySql::getInstance(); $sql = $db->query ("SELECT * FROM ".DB_PREFIX."blog inner join ".DB_PREFIX."sort WHERE hide='n' AND type='blog' AND sortop='y' AND sortid=sid order by date DESC limit 0,5"); while($row = $db->fetch_array($sql)){ if (!empty($row['excerpt'])){ preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $row['excerpt'], $match); if(empty($match[0][0])) { preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $row['content'], $match); } }else{ preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $row['content'], $match); } $logpost = !empty($row['excerpt']) ? $row['excerpt'] : ''.$row['content'].''; $num = rand(1,3); $img = isset($match[0][0]) ? $match[0][0] : '<img src="'.TEMPLATE_URL.'images/shuyong_net/'.$num.'.jpg">'; $date = gmdate('Y年m月d日', $row['date']); $content = strip_tags($logpost,''); $content = mb_substr($content,0,250,'utf-8');$comment = ($row['comnum'] != 0) ? '被吐槽<span>'.$row['comnum'].'</span>次' : '暂无吐槽'; $gid = $row['gid']; $tag = $db -> query("SELECT * FROM ".DB_PREFIX."tag WHERE gid LIKE '%,$gid,%'"); $out .='
<div class="flash_img2">
<div class="hdp_img"><a href="'.Url::log($row['gid']).'" title="'.$row['title'].'"   >'.$img.'</a></div>
<div class="hdp"><h4><a href="'.Url::log($row['gid']).'" title="'.$row['title'].'">'.$row['title'].'</a></h4>
<h5>日期:'.$date.'      分类:<a href="'.Url::sort($row['sortid']).'" title="查看 '.$row['sortname'].' 中的全部文章" rel="category tag">'.$row['sortname'].'</a>     共被围观 '.$row['views'].' 次    '.$comment.'</h5> 
<h6>'.$content.'...</h6></div></div>
'; } echo $out; }?>


以上未提供css代码,请自行折腾


admin 发布于  2015-7-22 23:35 

Emlog按天数时间调用热门文章列表 emlog

Emlog按天数时间调用随机热门文章列表

把以下代码复制到模板目录下的module.php里面,其中30*24*60*60中的30为天数,可自行修改

<?php
//30天按点击率排行文章
function sheli_hotlog($log_num) {
$db = MySql::getInstance();
$time = time();
$sql = "SELECT gid,title FROM ".DB_PREFIX."blog WHERE type='blog' AND date > $time - 30*24*60*60 ORDER BY `views` DESC LIMIT 0,$log_num";
$list = $db->query($sql);
while($row = $db->fetch_array($list)){ ?>
<li><a href="<?php echo Url::log($row['gid']); ?>" title="<?php echo $row['title']; ?>"><?php echo $row['title']; ?></a></li>
<?php } ?>
<?php } ?>

在需要的调用的地方输入<?php sheli_hotlog(10);?>调用,其中10为调用的数量。



admin 发布于  2015-7-22 12:15 

emlog插件 ---- SyntaxHighlighter 代码高亮2.2更新 emlog

此款emlog插件有以下功能:

  • 代码高亮(包含十几种常见代码自动高了着色);
  • pre标签自动换行(妈妈再也不用担心我的代码过长显示不全了-_-|);
  • 可复制,点击一下即可复制代码到剪贴板,方便使用;
  • 可新窗口查看代码,进行其他操作;
  • 可打印(貌似没啥用 -_-|)
  • 暂时就这么多.

有如下不足:

由于emlog 5.1.0版本采用KindEditor新版本,不支持原来的方法,因此不再支持5.1.0及以下版本

如果你的文章页或者是css中对pre标签有空值作用,可能会有bug显示.可自行调试解决,或者联系我,我会尽力帮你解决.

兼容性不是太好,如果安装后发现不能正常使用,请检查是否是某款插件冲突导致.

使用方法:

第一步:通过后台插件安装地址,上传安装插件,如果失败(一般是空间不支持)

请解压后用FTP上传至  网站根目录/content/plugins/ 路径下

第二步:在插件设置页面刷新,激活即可

<?php
/**
 * Confirms that the activation key that is sent in an email after a user signs
 * up for a new blog matches the key for that user and then displays confirmation.
 *
 * @package WordPress
 */

define( 'WP_INSTALLING', true );

/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wp-load.php' );

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

if ( !is_multisite() ) {
    wp_redirect( site_url( '/wp-login.php?action=register' ) );
    die();
}

if ( is_object( $wp_object_cache ) )
    $wp_object_cache->cache_enabled = false;

// Fix for page title
$wp_query->is_404 = false;

/**
 * Fires before the Site Activation page is loaded.
 *
 * @since 3.0.0
 */
do_action( 'activate_header' );

/**
 * Adds an action hook specific to this page that fires on wp_head
 *
 * @since MU
 */
function do_activate_header() {
    /**
     * Fires before the Site Activation page is loaded, but on the wp_head action.
     *
     * @since 3.0.0
     */
    do_action( 'activate_wp_head' );
}
add_action( 'wp_head', 'do_activate_header' );

/**
 * Loads styles specific to this page.
 *
 * @since MU
 */
function wpmu_activate_stylesheet() {
    ?>
    <style type="text/css">
        form { margin-top: 2em; }
        #submit, #key { width: 90%; font-size: 24px; }
        #language { margin-top: .5em; }
        .error { background: #f66; }
        span.h3 { padding: 0 8px; font-size: 1.3em; font-family: "Lucida Grande", Verdana, Arial, "Bitstream Vera Sans", sans-serif; font-weight: bold; color: #333; }
    </style>
    <?php
}
add_action( 'wp_head', 'wpmu_activate_stylesheet' );

get_header();
?>



插件下载:et_highlighter51.zip 备份链接:http://pan.baidu.com/s/1jGvqycI

欢迎大家下载使用,转载请注明出处,谢谢. Powered By Mrxn  https://mrxn.net

标签: 代码 php emlog

admin 发布于  2015-7-22 01:30 

php学习小计处理几个常见的错误 PHP

Deprecated: Function ereg_replace() is deprecated

在php5.3.0后的版本,取消了对ereg函数的支持,惹得若干程序需要改动,譬如我安装的zen-card1.3.8,颇不方便。
错误:Deprecated: Function ereg() is deprecated in ……
解决方法一:退回去用php5.2。(众人皆赞道:果是好法子!)

解决方法二:继续用php5.3,但是修改devel/devel.modul的460行:if ($errno & (E_ALL ^ E_NOTICE)) {改为if ($errno & (E_ALL & ~E_NOTICE & ~E_DEPRECATED)) {把丫deprecated错误给忽略掉。(众人皆又赞道:果……果……果是好法子!)

解决方法三:动程序鸟,把ereg换成preg_match,ereg_replace也需得换成preg_replace。只得注意的是ereg("^[0-9]")    需修改成   preg_match("/^[0-9]/") 无敌//必须加,哈哈。(众人皆俯首赞道:王道也!)



PHP之短标签开启设置

//php.ini中

short_open_tag = On

//除<?php ?>,可使用更灵活的调用方法

<? /*程序操作*/ ?>

<?=/*函数*/?>

这样可以解决很多错误.比如提示错误在某代码最后一行.


Deprecated: Function set_magic_quotes_runtime() is deprecated in
原因高版本的php把set_magic_quotes_runtime去了,解决办法:

//把
set_magic_quotes_runtime(0);
//替代成
ini_set("magic_quotes_runtime",0);

即可解析了.

标签: 编程 代码 php

admin 发布于  2015-7-21 20:21 

emlog教程--为网页添加动态背景 (背景轮播) emlog

以前文章 最近发现一个插件所以重新更新下本文

插件名称: jquery.backstretch.js

下面是 示例代码:

设置网页背景:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全屏背景</title>
    <script src="http://api.asilu.com/cdn/jquery.js,jquery.backstretch.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$.backstretch('http://api.asilu.com/cdn/img/bg/444.jpg');
</script>
</body>
</html>
多张张图片切换:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全屏背景切换</title>
    <script src="http://api.asilu.com/cdn/jquery.js,jquery.backstretch.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$.backstretch([
        'http://api.asilu.com/cdn/img/bg/444.jpg',
        'http://api.asilu.com/cdn/img/bg/445.jpg',
        'http://api.asilu.com/cdn/img/bg/446.jpg',
        'http://api.asilu.com/cdn/img/bg/447.jpg',
        'http://api.asilu.com/cdn/img/bg/448.jpg'
    ], {
        fade : 1000, // 动画时长
        duration : 2000 // 切换延时
});
</script>
</body>
</html>
该代码实现了, 背景图片的切换,带有切换效果的
第一个版本 切换效果用到了 jQuery 的动画,这个版本果断放弃 不需要 jQuery切换动画由CSS设置

具体代码如下
CSS 样式
JS 代码
HTML 就一个 div#bg简单实用

<meta http-equiv="Content-Type"content="text/html; charset=UTF-8"/>
<style>
div#bg {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: -10;
  background-position: center 0;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  -webkit-background-size: cover;
  -o-background-size: cover;
  zoom: 1;

  opacity:1;
  transition: opacity 1s linear;
  -moz-transition: opacity 1s linear;
  -webkit-transition: opacity 1s linear;
  -o-transition: opacity 1s linear;
}
</style>
<h1><a href="http://gouji.org/?post=317">代码出处</a></h1>
<div id="bg"></div>
<script>
// 定义图片路径 {num} 为 可变的图片序号
var bgImgUrl = 'http://api.asilu.com/cdn/img/bg/{num}.jpg', bgNum,
    bgImgArr = [],
    bgDiv = document.getElementById("bg");
// 组合数组 此处 200 为 图开始序号 结束 210
for (var i=200; i <= 210; i++){
  bgImgArr.push(bgImgUrl.replace('{num}', i));
}
setBGimg();
function setBGimg(d){
  if(!bgNum || bgNum > bgImgArr.length) bgNum = 0;
  bgDiv.style.opacity = .001;
  setTimeout(function(){
    bgDiv.style.backgroundImage = 'url('+ bgImgArr[bgNum] +')';
    bgDiv.style.opacity = 1;
  }, 1000);
  bgNum++;
  if(typeof d == 'undefined') 
    setInterval(function(){setBGimg(true);}, 6000);
    // 上一行的 6000 是背景图片自动切换时间(单位 毫秒)
}
</script>
原文为简爱博客,地址:http://www.gouji.org/?post=317


admin 发布于  2015-7-20 21:23 

想装逼?提升逼格?自慰?戳进来-Mrxn教你让文章浏览数随机增加 emlog

如题:想装逼?提升逼格?自慰?戳进来-Mrxn教你让文章浏览数随机增加

之前在论坛看过这种帖子,还有人求助...

看了一下各位给出的答案就是夹固定的数量.我想这么装逼不是很爽,不舒服呀.别人一看就知道了.你每次刷新网页增加的都是一样的.-_-|

今天我看自己也前的文章的时候发现了这篇文章:让emlog侧边栏显示彩色标签,随机显示标签,数量多少有你控制

于是就想到了这个.rand()php随机函数  于是就有了如下的装逼姿势:

/**
     * 增加阅读次数
     *
     * @param int $blogId
     */
    function updateViewCount($blogId) {
        $vnum=rand(1,7);
        $this->db->query("UPDATE " . DB_PREFIX . "blog SET views=views+'$vnum' WHERE gid=$blogId");
    }
友情提示:装逼有风险.请自行买保险!

这样修改了 include/mode/log_model.php 的第 302行 后,装逼姿势就优雅多了,有木有,rand(1,7)可以自己随便修改的.

总地来说.就装逼,然并卵!自慰吧.骚年!   Mrxn writed 2015/07/20


admin 发布于  2015-7-20 17:00 

Emlog显示评论者IP地理信息的三种方法-三种方法-重要的说两遍 emlog

emlog系统存储了评论人的IP地址,有的时候,需要显示该IP的真实地理地址,可以通过以下两种方法获得。

一、本地获得IP地理地址。通过本地查找本地IP数据库(纯真版)来获得,IP数据库可以到http://www.cz88.net/下载安装后,在安装目录里把qqwry.dat文件提取出来,放到emlog根目录即可。 (保证与index.php同在一个目录中)

在module.php中添加以下代码:


<?php
 //获取IP地理地址
$data = '254.254.254.254';
 class IpLocation {
      var $fp;
      var $firstip;
      var $lastip;
      var $totalip;

      function getlong() {
         $result = unpack('Vlong', fread($this->fp, 4));
         return $result['long'];
      }

     function getlong3() {
         $result = unpack('Vlong', fread($this->fp, 3).chr(0));
         return $result['long'];
      }

      function packip($ip) {
         return pack('N', intval(ip2long($ip)));
      }

      function getstring($data = "") {
         $char = fread($this->fp, 1);
         while (ord($char) > 0) {
             $data .= $char;
             $char = fread($this->fp, 1);
         }
         return $data;
      }

      function getarea() {
         $byte = fread($this->fp, 1);
         switch (ord($byte)) {
             case 0:
                $area = "";
                break;
             case 1:
             case 2:
                fseek($this->fp, $this->getlong3());
                $area = $this->getstring();
                break;
             default: 
                $area = $this->getstring($byte);
                break;
         }
         return $area;
         }

      function getlocation($ip) {

         if (!$this->fp) return null;
         $location['ip'] = gethostbyname($ip); 
         $ip = $this->packip($location['ip']);
         $l = 0; 
         $u = $this->totalip;
         $findip = $this->lastip;
         while ($l <= $u) { 
             $i = floor(($l + $u) / 2); 
             fseek($this->fp, $this->firstip + $i * 7);
             $beginip = strrev(fread($this->fp, 4));
             if ($ip < $beginip) {
                $u = $i - 1;
             }
             else {
                fseek($this->fp, $this->getlong3());
                $endip = strrev(fread($this->fp, 4));
                if ($ip > $endip) {
                    $l = $i + 1; 
                }
                else {
                    $findip = $this->firstip + $i * 7;
                    break;
                }
             }
         }
         fseek($this->fp, $findip);
         $location['beginip'] = long2ip($this->getlong()); 
         $offset = $this->getlong3();
         fseek($this->fp, $offset);
         $location['endip'] = long2ip($this->getlong());
         $byte = fread($this->fp, 1); 
         switch (ord($byte)) {
             case 1: 
                $countryOffset = $this->getlong3();
                fseek($this->fp, $countryOffset);
                $byte = fread($this->fp, 1);
                switch (ord($byte)) {
                    case 2: 
                       fseek($this->fp, $this->getlong3());
                       $location['country'] = $this->getstring();
                       fseek($this->fp, $countryOffset + 4);
                       $location['area'] = $this->getarea();
                       break;
                    default: 
                       $location['country'] = $this->getstring($byte);
                       $location['area'] = $this->getarea();
                       break;
                }
                break;
             case 2:
                fseek($this->fp, $this->getlong3());
                $location['country'] = $this->getstring();
                fseek($this->fp, $offset + 8);
                $location['area'] = $this->getarea();
                break;
             default: 
                $location['country'] = $this->getstring($byte);
                $location['area'] = $this->getarea();
                break;
         }
         if ($location['country'] == " CZNET") { 
             $location['country'] = "未知";
         }
         if ($location['area'] == " CZNET") {
             $location['area'] = "";
         }
         return $location;
      }

      function IpLocation($filename = "qqwry.dat") {
         $this->fp = 0;
         if (($this->fp = @fopen($filename, 'rb')) !== false) {
             $this->firstip = $this->getlong();
             $this->lastip = $this->getlong();
             $this->totalip = ($this->lastip - $this->firstip) / 7;
             register_shutdown_function(array(&$this, '_IpLocation'));
         }
      }

      function _IpLocation() {
         if ($this->fp) {
             fclose($this->fp);
         }
         $this->fp = 0;
      }
 }

 function getaddress($myip){
 $ipOrDomain=$myip;
 $iplocation = new IpLocation();
 $location = $iplocation->getlocation($ipOrDomain);
 $address=mb_convert_encoding($location['country'].$location['area'], "utf-8", "gbk");
 return $address;
 }
 ?>

然后在需要显示的地方插入:



<?php echo getaddress($comment['ip']);?>



即可。

 

二、通过远程网站相关接口实现。

在module.php中添加以下代码:


 <?php
 //blog:获取IP地址所在地,提取新浪IP接口
function getaddress($ip)
 {
 //调用sina查询接口
$str = file_get_contents("http://counter.sina.com.cn/ip?ip=".$ip);
 //转换字符集
$str = mb_convert_encoding($str,"UTF-8","GBK");  
 //匹配结果
preg_match_all('/[\x{4e00}-\x{9fa5}]+/u',$str,$get);
 //将数组转换成字符串
$add = implode('-',$get[0]);
 //返回结果
return $add;
 }
 ?>

然后在需要显示的地方插入:



<?php echo getaddress($comment['ip']);?>

即可。

图片显示方式:

<a title= <?php echo getaddress($comment['ip']);?>>&nbsp;<img src="./content/templates/default/images/ip.png"></a>
其中ip.png这个图标会显示在评论人的后面,图片自找,鼠标放上去会显示地理地址。

另一种方法显示IP:


1.首先在当前模板的module.php最后添加如下代码:


    <?php
    function convertip($ip) {   
        $dat_path = EMLOG_ROOT.'/content/templates/你的模板文件/QQWry.Dat'; //*数据库路径*//  
        if(!$fd = @fopen($dat_path, 'rb')){   
            return 'IP数据库文件不存在或者禁止访问或者已经被删除!';   
        }   
        $ip = explode('.', $ip);   
        $ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];   
        $DataBegin = fread($fd, 4);   
        $DataEnd = fread($fd, 4);   
        $ipbegin = implode('', unpack('L', $DataBegin));   
        if($ipbegin < 0) $ipbegin += pow(2, 32);   
        $ipend = implode('', unpack('L', $DataEnd));   
        if($ipend < 0) $ipend += pow(2, 32);   
        $ipAllNum = ($ipend - $ipbegin) / 7 + 1;   
        $BeginNum = 0;   
        $EndNum = $ipAllNum;   
        while($ip1num>$ipNum || $ip2num<$ipNum) {   
            $Middle= intval(($EndNum + $BeginNum) / 2);   
            fseek($fd, $ipbegin + 7 * $Middle);   
            $ipData1 = fread($fd, 4);   
            if(strlen($ipData1) < 4) {   
                fclose($fd);   
                return '系统出错!';   
            }   
            $ip1num = implode('', unpack('L', $ipData1));   
            if($ip1num < 0) $ip1num += pow(2, 32);   
            if($ip1num > $ipNum) {   
                $EndNum = $Middle;   
                continue;   
            }   
            $DataSeek = fread($fd, 3);   
            if(strlen($DataSeek) < 3) {   
                fclose($fd);   
                return '系统出错!';   
            }   
            $DataSeek = implode('', unpack('L', $DataSeek.chr(0)));   
            fseek($fd, $DataSeek);   
            $ipData2 = fread($fd, 4);   
            if(strlen($ipData2) < 4) {   
                fclose($fd);   
                return '系统出错!';   
            }   
            $ip2num = implode('', unpack('L', $ipData2));   
            if($ip2num < 0) $ip2num += pow(2, 32);   
            if($ip2num < $ipNum) {   
                if($Middle == $BeginNum) {   
                    fclose($fd);   
                    return '未知';   
                }   
                $BeginNum = $Middle;   
            }   
        }   
        $ipFlag = fread($fd, 1);   
        if($ipFlag == chr(1)) {   
            $ipSeek = fread($fd, 3);   
            if(strlen($ipSeek) < 3) {   
                fclose($fd);   
                return '系统出错!';   
            }   
            $ipSeek = implode('', unpack('L', $ipSeek.chr(0)));   
            fseek($fd, $ipSeek);   
            $ipFlag = fread($fd, 1);   
        }   
        if($ipFlag == chr(2)) {   
            $AddrSeek = fread($fd, 3);   
            if(strlen($AddrSeek) < 3) {   
                fclose($fd);   
                return '系统出错!';   
            }   
            $ipFlag = fread($fd, 1);   
            if($ipFlag == chr(2)) {   
                $AddrSeek2 = fread($fd, 3);   
                if(strlen($AddrSeek2) < 3) {   
                    fclose($fd);   
                    return '系统出错!';   
                }   
                $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));   
                fseek($fd, $AddrSeek2);   
            } else {   
                fseek($fd, -1, SEEK_CUR);   
            }   
            while(($char = fread($fd, 1)) != chr(0))   
            $ipAddr2 .= $char;   
            $AddrSeek = implode('', unpack('L', $AddrSeek.chr(0)));   
            fseek($fd, $AddrSeek);   
            while(($char = fread($fd, 1)) != chr(0))   
            $ipAddr1 .= $char;   
        } else {   
            fseek($fd, -1, SEEK_CUR);   
            while(($char = fread($fd, 1)) != chr(0))   
            $ipAddr1 .= $char;   

            $ipFlag = fread($fd, 1);   
            if($ipFlag == chr(2)) {   
                $AddrSeek2 = fread($fd, 3);   
                if(strlen($AddrSeek2) < 3) {   
                    fclose($fd);   
                    return '系统出错!';   
                }   
                $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));   
                fseek($fd, $AddrSeek2);   
            } else {   
                fseek($fd, -1, SEEK_CUR);   
            }   
            while(($char = fread($fd, 1)) != chr(0)){   
                $ipAddr2 .= $char;   
            }   
        }   
        fclose($fd);   
        if(preg_match('/http/i', $ipAddr2)) {   
            $ipAddr2 = '';   
        }   
        $ipaddr = "$ipAddr1 $ipAddr2";   
        $ipaddr = preg_replace('/CZ88.Net/is', '', $ipaddr);   
        $ipaddr = preg_replace('/^s*/is', '', $ipaddr);   
        $ipaddr = preg_replace('/s*$/is', '', $ipaddr);   
        if(preg_match('/http/i', $ipaddr) || $ipaddr == '') {   
            $ipaddr = '未知';   
        }   
        $ipaddr = iconv('gbk', 'utf-8//IGNORE', $ipaddr);    
        if( $ipaddr != '  ' )   
            return $ipaddr;   
        else  
            $ipaddr = '评论者来自火星,无法或者其所在地!';   
            return $ipaddr;   
    }
    ?>

然后再在评论中添加要你要显示位置。原作者未给出图片提示的代码。

纯文字显示代码:

<?php echo convertip($comment['ip']); ?>

图片title显示代码:



<img src="<?php echo BLOG_URL; ?>XXX/ip.png" alt="<?php echo convertip($comment['ip']); ?>" title="<?php echo convertip($comment['ip']); ?>"   width="16" height="16" class="useragent" data-bd-imgshare-binded="1">

上面代码中的XXX/ip.png是图片路径

其中使用到的纯真数据库以及图片自己下载,本博主暂不提供。



admin 发布于  2015-7-19 16:32 

身份证号码验证算法 (PHP JavaScript 代码) 技术文章

18 位身份证号码结构

1-2 位省、自治区、直辖市代码
3-4 位地级市、盟、自治州代码
5-6 位县、县级市、区代码
7-14 位出生年月日,比如19670401代表1967年4月1日
15-17 位为顺序号,其中17位 为性别 男为单数,女为双数
18 位为校验码,0-9和X。作为尾号的校验码 (计算方法下面有)
举例:
130503 19070101 0013 这个身份证号的含义: 13为河北,05为邢台,03为桥西区,出生日期为1967年4月1日,顺序号为001 (1 性别 男),2为校验码。


15 位的身份证相比 18 出生年月 中的 年 为两位, 且缺少 最后一位 校验码

身份证校验码的计算方法

计算最后一位校验码的具体步骤

  1. 17 号码 加权求和 注: 1-17位 加权因子分别为 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
  2. 上一步所求的和 取模 (下面的 代码 用的是 取余)
  3. 上一步的 结果 0 - 10 分别对应 的 校验码 为 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2


判断身份证号码是否正确的 函数

下面是 判断身份证号码是否正确的 函数封装 分别为 PHP JS

传入 身份证号码 返回校验结果 true false

/* PHP 验证 身份证号 */
function ckeckIdCard($id){
    static $codeArr = array(1,0,'X',9,8,7,6,5,4,3,2),
        $keyArr = array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
    $id = strtoupper($id);
    if(!preg_match('/^[\d]{17}[\dX]{1}$/', $id)) return false;

    $num = 0;
    for($i=0; $i<17; $i++){
        $num += $id[$i] * $keyArr[$i];
    }
    $key = $num % 11;
    return substr($id, -1) == $codeArr[$key];
}
/* JS 验证 身份证号 */
function ckeckIdCard($id){
    var $codeArr = [1,0,'X',9,8,7,6,5,4,3,2],
        $keyArr = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
    $id = $id.toUpperCase();
    if(!/^[\d]{17}[\dX]{1}$/.test($id)) return false;

    $num = 0;
    for($i=0; $i<17; $i++){
        $num += $id[$i] * $keyArr[$i];
    }
    $key = $num % 11;
    return $id.slice(-1) == $codeArr[$key];
}


原文出自简爱博客 http://www.gouji.org/?post=378 觉得不错 转载.如有不便,请联系管理员.


admin 发布于  2015-7-17 19:13 

MySQL学习之多表更新一步到位 代码人生

首先说明:个人学习笔记而已,不喜勿看,以免不适.

mysql> CREATE TABLE IF NOT EXISTS tdb_goods_cates(

-> cate_id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

-> cate_name VARCHAR(40) NOT NULL)

-> default charset=utf8

-> ;

Query OK, 0 rows affected (0.02 sec)



mysql> set NAMES gbk;

Query OK, 0 rows affected (0.00 sec)


在要创建的表后加 DEFAULT CHARSET=utf8; 防止中文乱码

链接类型
INNER JOIN 内连接
JOIN, CROSS JOIN, INNER JOIN 是等价的
RIGHT [OUTER] JOIN 右外链接

连接条件:
使用 ON 关键字来设定连接条件,也可以使用 WHERE 来代替。
通常使用 ON 关键字来设定连接条件
使用 WHERE 关键字进行结果集记录的过滤
内连接:返回左表及右表符合连接条件的记录(即两表的交集部分)

UPDATE table_references SET col_name1={express|DEFAULT} [,col_name2={expr2|DEFAULT}]...[WHERE where_condition]

语法结构
table_reference
{[INNER|CROSS]JOIN|{LEFT|RIGHT}[OUTER]JOIN}
Ttable_reference
ON condition_expr

外连接:
以左外连接为例:
A LEFT JOIN B join_condition
数据表B的结果集依赖于数据表A
数据表A的结果集根据左连接条件依赖所有数据表(B表除外)
左外连接条件决定如何检索数据表B(在没有指定WHERE条件的情况下)
如果数据表A的某条记录符合WHERE条件,但是在数据表B不存在符合连接条件的记录,将生成一个所有列为空的额外的B行
内连接:
使用内连接查找的记录在连接数据表中不存在,并且在WHERE子句中尝试一下操作:column_name IS NULL 。如果 column_name 被指定为 NOT NULL,MySQL将在找到符合连接着条件的记录后停止搜索更多的行(查找冲突)

mysql> UPDATE tdb_goods INNER JOIN tdb_goods_cates ON goods_cate=cate_name
-> SET goods_cate=cate_id;
Query OK, 22 rows affected (0.01 sec)
Rows matched: 22 Changed: 22 Warnings: 0

mysql> CREATE TABLE IF NOT EXISTS tdb_goods_brands(
musqlbrand_id SMALLINT PRIMARY KEY AUTO_INCREMENT,
brand_name VARCHAR(40) NOT NUL)
DEFAULT CHARSET=UTF8
SELECT brand_name FROM tdb_goods GROUP BY brand_name;
多表更新 一步到位 在创建表的时候就将选择(select)插入(insert)一起搞定
mysql> UPDATE tdb_goods INNER JOIN tdb_goods_brands ON brand_name = brand_name
SET brand_name = brand_id;
这样将会出现错误 因为MySQL不能分清brand_name所指的是哪一个表的字段,因此 需要设置别名或者是字段前面加上表明
mysql> UPDATE tdb_goods AS A INNER JOIN tdb_goods_brands AS B ON A.brand_name =
B.brand_name SET A.brand_name = B.brand_id;
一般情况下使用别名 比较方便.
但是
| goods_cate | varchar(40)

| brand_name | varchar(40)
最好做如下修改
mysql> ALTER TABLE tdb_goods
-> CHANGE goods_cate cate_id SMALLINT UNSIGNED NOT NULL,
-> CHANGE brand_name brand_id SMALLINT UNSIGNED NOT NULL;
Query OK, 23 rows affected, 1 warning (0.06 sec)
Records: 23 Duplicates: 0 Warnings: 1
使用ALTER TABLE 修改指定表的字段或者字段的值


admin 发布于  2015-7-12 14:48 

MySQL的增(insert)删(delete)改(update)查(select)学习小计 代码人生


记录操作://插入数据
INSERT [INTO] tbl_name [(col_name,...)] {VALUES | VALUE} ({expr|DEFAULT},...),(...),...
INSERT [INTO] tbl_name SET col_name={expr|DEFAULT},...
INSERT [INTO] tbl_name [(col_name,...)] SELECT...

UPDATE://更新数据
单表更新/UPDATE [LOW_PRIORITY][IGNORE] table_reference SET col_name1={expr1|DEFAULT},[col_name2={expr2|DEFAULT}]...[WHERE where_condition]
多表更新/...

DELETE : //删除数据
单表删除/DELETE FROM tbl_name [WHERE where_condition}
多表删除/...

SELECT: //查询
SELECT select_expr [,select_expr ...]
[
FROM
WHERE
GROUP BY {col_name | position}[ASC|DESC],...
LIMIT {[offset,] row_count|row_count OFFSET offset
]

解决乱码的问题:
1.show variables like "%char%";
类似set character_set_results=utf8;,能改的都改为uft8
2.在要创建的表后加ENGINE=InnoDB DEFAULT CHARSET=utf8;

以utf8为例:
建表时,应当加上CREATE TABLE IF NOT EXISTS $tableName($paramArray) default charset=utf8选项;
插入数据前,应当先设置编码:SET NAMES utf8|gbk|gb2312;
然后插入数据:INSERT $tableName($param2insertArray) VALUES($valueArray);

set names gbk:表示只是设置客户端的显示编码,不会影响数据编码


admin 发布于  2015-7-10 15:52