首页 > 编程技术 > php

PHP使用星号替代用户名手机和邮箱

发布时间:2016-11-25 15:33

PHP使用星号替代用户名手机和邮箱这个在许多的活动界面会看到如淘宝的购物界面中的一些客户的支付宝号都是隐藏掉的哦,下面我们来看一下它的使用方法吧。

<?php

function hideStar($str) { //用户名、邮箱、手机账号中间字符串以*隐藏
    if (strpos($str, '@')) {
        $email_array = explode("@", $str);
        $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($str, 0, 3); //邮箱前缀
        $count = 0;
        $str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count);
        $rs = $prevfix . $str;
    } else {
        $pattern = '/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i';
        if (preg_match($pattern, $str)) {
            $rs = preg_replace($pattern, '$1****$2', $str); // substr_replace($name,'****',3,4);
        } else {
            $rs = substr($str, 0, 3) . "***" . substr($str, -1);
        }
    }
    return $rs;
}
?>

<?php
$account = "111cn.net";
$email = "416148489@qq.com";
$phone = "18005152525";
?>
<!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>演示:PHP以星号隐藏用户名手机和邮箱</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
        <link rel="stylesheet" type="text/css" href="http://www.111cn.net  /jquery/css/common.css" />
        <style type="text/css">
        </style>
    </head>
    <body>
        <div class="head">
            <div class="head_inner clearfix">
                <ul id="nav">
                    <li><a href="http://www.111cn.net  ">首 页</a></li>
                    <li><a href="http://www.111cn.net  /templates">网站模板</a></li>
                    <li><a href="http://www.111cn.net  /js">网页特效</a></li>
                    <li><a href="http://www.111cn.net  /php">PHP</a></li>
                    <li><a href="http://www.111cn.net  /site">精选网址</a></li>
                </ul>
                <a class="logo" href="http://www.111cn.net  "><img" width=100% src="http://www.111cn.net  /Public/images/logo.jpg" alt="素材火logo" /></a>
            </div>
        </div>
        <div class="container">
            <div class="demo">
                <h2 class="title"><a href="http://www.111cn.net  /js/548.html">教程:PHP以星号隐藏用户名手机和邮箱</a></h2>

                <table width="100%" class="table_parameters">
                    <tr class="tr_head">
                        <td>账号</td>
                        <td>邮箱</td>
                        <td>手机</td>
                    </tr>
                    <tr>
                        <td><?php echo $account; ?></td>
                        <td><?php echo $email; ?></td>
                        <td><?php echo $phone; ?></td>
                    </tr>
                    <tr class="red">
                        <td><?php echo hideStar($account); ?></td>
                        <td><?php echo hideStar($email); ?></td>
                        <td><?php echo hideStar($phone); ?></td>
                    </tr>
                </table>
            </div>
        </div>
      
    </body>
</html>

php编译安装碰到各种的问题了,我们这里整理了一篇关于解决php编译中遇到各种error办法的文章,希望此文章能够为各位带来帮助呀。
1) Configure: error: xml2-config not found. Please check your libxml2 installation.

 

Solutions :

 

Quote:

 

 

 

# yum install libxml2 libxml2-devel

 

 

 

2) Checking for pkg-config… /usr/bin/pkg-config configure: error: Cannot find OpenSSL’s <evp.h>

 

Solutions :

 

Quote:

 

 

 

# yum install openssl openssl-devel

 

 

 

3) Configure: error: Please reinstall the BZip2 distribution

 

Solutions :

 

Quote:

 

 

 

# yum install bzip2 bzip2-devel

 

 

 

4) Configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/

 

Solutions :

 

Quote:

 

 

 

# yum install curl curl-devel

 

 

 

5) Configure: error: libjpeg.(also) not found.

 

Solutions :

 

Quote:

 

 

 

# yum install libjpeg libjpeg-devel

 

 

 

6) Configure: error: libpng.(also) not found.

 

Solutions :

 

Quote:

 

 

 

# yum install libpng libpng-devel

 

 

 

7) Configure: error: freetype.h not found.

 

Solutions :

 

Quote:

 

 

 

#yum install freetype-devel

 

 

 

8) Configure: error: Unable to locate gmp.h

 

Solutions :

 

Quote:

 

 

 

# yum install gmp-devel

 

 

 

9) Configure: error: Cannot find MySQL header files under /usr. Note that the MySQL client library is not bundled anymore!

 

Solutions :

 

Quote:

 

 

 

# yum install mysql-devel

 

 

 

10) Configure: error: Please reinstall the ncurses distribution

 

Solutions :

 

Quote:

 

 

 

# yum install ncurses ncurses-devel

 

 

 

11) Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

 

Solutions :

 

Quote:

 

 

 

# yum install unixODBC-devel

 

 

 

12) Configure: error: Cannot find pspell

 

Solutions :

 

Quote:

 

 

 

# yum install pspell-devel

 

 

 

13) configure: error: mcrypt.h not found. Please reinstall libmcrypt.

 

Solutions :

 

Quote:

 

 

 

# yum install libmcrypt libmcrypt-devel

 

 

 

14) Configure: error: snmp.h not found. Check your SNMP installation.

 

Solutions :

 

Quote:

 

 

 

# yum install net-snmp net-snmp-devel

 

 

 

15)configure: error: Please reinstall libmhash – I cannot find mhash.h

 

 

 

#yum install mhash-devel
文章分页用到比较多同时使用过cms的朋友也碰到过都具备了文章分页功能了,下面我们自己来看一个关于文章分页的例子,具体的操作步骤如下所示,希望文章能够帮助到各位朋友


content.txt

这个文件里面放的是内容了,如果你是与mysql数据库结合的话只要把把这一句换成你的数据库的内容即可。

index.php文件

      
<link rel="stylesheet" type="text/css" href="http:///jquery/css/common.css" />
        <style type="text/css">
            .demo{width:80%;margin:50px auto 10px auto;padding:10px;}
            .demo p{line-height:30px;text-indent:2em}
            .demo h3{font-size:24px;text-align:center;padding:10px}
            @media (max-width: 480px){
                .demo{width:360px;margin:50px auto 10px auto;padding:10px;}
                .demo img{width:90%}
                .demo h3{font-size:1.5em;line-height:1.9em}
            }
            .pages{text-align:center;border-top:1px solid #d3d3d3;margin-top:10px; padding-top:10px}
            .pages a{display:inline-block;margin:4px;padding:4px 8px;background:#f9f9f9;border:1px solid #d9d9d9}
            .pages a.cur{cursor:default;background:#d3d3d3;color:#434343}
            .pages a.cur:hover{text-decoration:none}
        </style>

        <div class="head">
            <div class="head_inner clearfix">
                <ul id="nav">
                    <li><a href="http://">首 页</a></li>
                    <li><a href="http:///templates">网站模板</a></li>
                    <li><a href="http:///js">网页特效</a></li>
                    <li><a href="http:///php">PHP</a></li>
                    <li><a href="http:///site">精选网址</a></li>
                </ul>
                <a class="logo" href="http://"><img" width=100% src="http:///Public/images/logo.jpg" alt="素材火logo" /></a>
            </div>
        </div>
        <div class="container">
            <div class="demo">
                <h2 class="title"><a href="http:///js/639.html">教程:PHP长文章分页教程与演示</a></h2>
                <h3>未来10年千万人将没有工作?</h3>
                <?php
                include('page.class.php');
                //自定义的长文章字符串,可以包含 html 代码,若字符串中有手动分页符 {nextpage} 则优先按手动分页符进行分页   
                $content = file_get_contents('content.txt');
                $ipage = isset($_GET["ipage"]) ? intval($_GET["ipage"]) : 1;
                $CP = new cutpage($content);
                $page = $CP->cut_str();
                echo $page[$ipage - 1];
                echo '<div class="pages">' . $CP->pagenav() . '</div>';
                ?>


            </div>
        </div>

长文章分页类  page.class.php

<?php   
/* 
*  长文章分页类    
*/ 
    class cutpage{   
        private $pagestr;       //被切分的内容   
        private $pagearr;       //被切分文字的数组格式   
        private $sum_word;      //总字数(UTF-8格式的中文字符也包括)   
        private $sum_page;      //总页数   
        private $page_word;     //一页多少字   
        private $cut_tag;       //自动分页符   
        private $cut_custom;    //手动分页符   
        private $ipage;         //当前切分的页数,第几页   
        private $url;   
  
        function __construct($pagestr,$page_word=1000){   
            $this->page_word = $page_word;   
            $this->cut_tag = array("</table>", "</div>", "</p>", "<br/>", "”。", "。", ".", "!", "……", "?", ",");   
            $this->cut_custom = "{nextpage}";   
            $tmp_page = isset($_GET["ipage"]) ? intval($_GET["ipage"]) : 1;   
            $this->ipage = $tmp_page>1?$tmp_page:1;
   $this->pagestr = $pagestr;
        }   
        //统计总字数   
        function get_page_word(){   
            $this->sum_word = $this->strlen_utf8($this->pagestr);   
            return $this->sum_word;   
        }   
        /*  统计UTF-8编码的字符长度 
         *  一个中文,一个英文都为一个字 
         */ 
        function strlen_utf8($str){   
           $i = 0;   
           $count = 0;   
           $len = strlen ($str);   
           while ($i < $len){   
               $chr = ord ($str[$i]);   
               $count++;   
               $i++;   
               if ($i >= $len)   
                   break;   
               if ($chr & 0x80){   
                   $chr <<= 1;   
                   while ($chr & 0x80) {   
                       $i++;   
                       $chr <<= 1;   
                   }   
               }   
           }   
           return $count;   
        }   
        //设置自动分页符号   
        function set_cut_tag($tag_arr=array()){   
            $this->cut_tag = $tag_arr;   
        }   
        //设置手动分页符   
        function set_cut_custom($cut_str){   
            $this->cut_custom = $cut_str;   
        }   
        function show_cpage($ipage=0){   
            $this->cut_str();   
            $ipage = $ipage ? $ipage:$this->ipage;   
            return $this->pagearr[$ipage];   
        }   
        function cut_str(){   
            $str_len_word = strlen($this->pagestr);     //获取使用strlen得到的字符总数   
            $i = 0;   
            if ($str_len_word<=$this->page_word){   //如果总字数小于一页显示字数   
                $page_arr[$i] = $this->pagestr;   
            }else{   
                if (strpos($this->pagestr, $this->cut_custom)){   
                    $page_arr = explode($this->cut_custom, $this->pagestr);   
                }else{   
                    $str_first = substr($this->pagestr, 0, $this->page_word);   //0-page_word个文字    cutStr为func.global中的函数   
                    foreach ($this->cut_tag as $v){   
                        $cut_start = strrpos($str_first, $v);       //逆向查找第一个分页符的位置   
                        if ($cut_start){   
                            $page_arr[$i++] = substr($this->pagestr, 0, $cut_start).$v;   
                            $cut_start = $cut_start + strlen($v);   
                            break;   
                        }   
                    }   
                    if (($cut_start+$this->page_word)>=$str_len_word){  //如果超过总字数   
                        $page_arr[$i++] = substr($this->pagestr, $cut_start, $this->page_word);   
                    }else{   
                        while (($cut_start+$this->page_word)<$str_len_word){   
                            foreach ($this->cut_tag as $v){   
                                $str_tmp = substr($this->pagestr, $cut_start, $this->page_word);        //取第cut_start个字后的page_word个字符   
                                $cut_tmp = strrpos($str_tmp, $v);       //找出从第cut_start个字之后,page_word个字之间,逆向查找第一个分页符的位置   
                                if ($cut_tmp){   
                                    $page_arr[$i++] = substr($str_tmp, 0, $cut_tmp).$v;   
                                    $cut_start = $cut_start + $cut_tmp + strlen($v);   
                                    break;   
                                }   
                            }     
                        }   
                        if (($cut_start+$this->page_word)>$str_len_word){   
                            $page_arr[$i++] = substr($this->pagestr, $cut_start, $this->page_word);   
                        }   
                    }   
                }   
            }   
            $this->sum_page = count($page_arr);     //总页数   
            $this->pagearr = $page_arr; 
   return $page_arr;
        }   
        //显示上一条,下一条   
        function pagenav(){   
            $this->set_url();   
            $str = '';
   
   //$str .= $this->ipage.'/'.$this->sum_page;
   
   for($i=1;$i<=$this->sum_page;$i++){
    if($i==$this->ipage) {
     $str.= "<a href='#' class='cur'>".$i."</a> ";
    }else{
     $str.= "<a href='".$this->url.$i."'>".$i."</a> ";
    }
   }
   
             
            return $str;   
        }   
  function show_prv_next2(){   
            $this->set_url();   
            $str = '';
   
   
   
            if ($this->sum_page>1 and $this->ipage>1){   
                $str.= "<a href='".$this->url.($this->ipage-1)."'>上一页</a> ";   
            }  
   if ($this->sum_page>1 and $this->ipage<$this->sum_page){   
                $str .= "<a href='".$this->url.($this->ipage+1)."'>下一页</a>";   
            }      
            return $str;   
        }   
        function show_page_select(){   
            if ($this->sum_page>1){   
                $str = "   <select onchange='location.href=this.options[this.selectedIndex].value'>";   
                for ($i=1; $i<=$this->sum_page; $i++){   
                    $str.= "<option value='".$this->url.$i."' ".(($this->ipage)==$i ? " selected='selected'":"").">第".$i."页</option>";   
                }   
                $str.= "</select>";   
            }   
            return $str;   
        }   
        function show_page_select_wap(){   
            if ($this->sum_page>1){   
                $str = "<select ivalue='".($this->ipage-1)."'>";   
                for ($i=1; $i<=$this->sum_page; $i++){   
                    $str.= "<option onpick='".$this->url.$i."'>第".$i."节</option>";   
                }   
                $str.= "</select>";   
            }   
            return $str;   
        }   
        function set_url(){   
            parse_str($_SERVER["QUERY_STRING"], $arr_url);   
            unset($arr_url["ipage"]);   
            if (empty($arr_url)){   
                $str = "ipage=";   
            }else{   
                $str = http_build_query($arr_url)."&ipage=";   
            }   
            $this->url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$str;   
        }   
    }   
?>

php实现上一篇下一篇这个主要是通过sql来根据当前的id来进行判断然后筛选出当前ID之前的数据或ID之后的数据了就这么简单,具体的我们来看看。

实现网站文章里面上一篇和下一篇的sql语句的写法。

当前文章的id为 $article_id,当前文章对应分类的id是$cat_id,那么上一篇就应该是:
代码如下

SELECT max(article_id) FROM article WHERE article_id < $article_id AND cat_id=$cat_id;

执行这段sql语句后得到 $max_id,然后

SELECT article_id, title FROM article WHERE article_id = $max_id;

简化一下,转为子查询即:

SELECT article_id, title FROM article WHERE article_id = (SELECT max(article_id) FROM article WHERE article_id < $article_id AND cat_id=$cat_id);

下一篇为:

代码如下

SELECT min(article_id) FROM article WHERE article_id > $article_id AND cat_id=$cat_id;

执行这段sql语句后得到 $min_id,然后

SELECT article_id, title FROM article WHERE article_id = $min_id;

简化一下,转为子查询即:
代码如下

SELECT article_id, title FROM article WHERE article_id = (SELECT min(article_id) FROM article WHERE article_id > $article_id AND cat_id=$cat_id);

最后讲一下有很多朋友喜欢使用下面语句

上一篇:
代码如下

select id from table where id10 limit 0,1;

这样肯定没有问题,但是是性能感觉不怎么地。

sql语句优化

你可以使用union all来实现一条语句取3行数据,但是前提是3个查询的字段要相同

这个查询出来的结果第一行就是上一篇文章,第二行是当前文章,第三行是下一篇文章
代码如下

(select id from table where id < 10 order by id asc limit 1) union all (select id from table where id = 10) union all (select id from table where id > 10 order by id desc limit 1);

现在来看一些cms中的例子phpcms 实现上一篇下一篇

获取当前浏览文章id

$id = isset($_GET['id']) > 0 ? intval($_GET['id']) : "";
下一篇文章

$query = mysql_query("SELECT id,title FROM article WHERE id>'$id' ORDER BY id ASC LIMIT 1");
$next = mysql_fetch_array($query);

上一篇文章

$query = mysql_query("SELECT id,title FROM article WHERE id <'$id' ORDER BY id DESC LIMIT 1");
$prev = mysql_fetch_array($query);


   


        "><?php echo="">        
   


   


        "><?php echo=""> 
   


session在php中用来跨页面记录用户信息了通用于服务器登录了,但今天配置的环境发现session无法正常的传递了,那么碰到php session无法保存问题如何来处理呢,具体的如下。

因为正确的验证码结果已经经过加密之后保存在了session中,所有用于输入的验证码会跟session中的进行比对,从而判断验证码是否输入有误!

既然老是显示:"验证码输入有误"

说明session中保存到结果可能有问题。然后,dump下session,发现结果为null......

解决办法:

使用phpinfo查看session信息,找出session的保存路径,然后给其设置写入的权限即可

如果无法解决可以参考下面

现在我们来抛开cookie使用session,主要途径有三条:

1、设置php.ini中的session.use_trans_sid = 1或者编译时打开打开了–enable-trans-sid选项,
让PHP自动跨页传递session id。
2、手动通过URL传值、隐藏表单传递session id。
3、用文件、数据库等形式保存session_id,在跨页过程中手动调用。

例子,php利用session登录退出的简单例子

登录

<?php
//使用会话内存储的变量值之前必须先开启会话
session_start();
//使用一个会话变量检查登录状态
if(isset($_SESSION['username'])){
    echo 'You are Logged as '.$_SESSION['username'].'<br/>';
    //点击“Log Out”,则转到logOut页面进行注销
    echo '<a href="logOut.php"> Log Out('.$_SESSION['username'].')</a>';
}
/**在已登录页面中,可以利用用户的session如$_SESSION['username']、
 * $_SESSION['user_id']对数据库进行查询,可以做好多好多事情*/
?>

退出

<?php
//即使是注销时,也必须首先开始会话才能访问会话变量
session_start();
//使用一个会话变量检查登录状态
if(isset($_SESSION['user_id'])){
    //要清除会话变量,将$_SESSION超级全局变量设置为一个空数组
    $_SESSION = array();
    //如果存在一个会话cookie,通过将到期时间设置为之前1个小时从而将其删除
    if(isset($_COOKIE[session_name()])){
        setcookie(session_name(),'',time()-3600);
    }
    //使用内置session_destroy()函数调用撤销会话
    session_destroy();
}
//location首部使浏览器重定向到另一个页面
$home_url = 'logIn.php';
header('Location:'.$home_url);
?>

标签:[!--infotagslink--]

您可能感兴趣的文章: