PHP 长文章分页函数

 更新时间:2016年11月25日 16:02  点击:2060

<?php function ff_page($content,$page)
{
global $expert_id;
$PageLength = 2000; //每页字数
$CLength = strlen($content);
$PageCount = floor(($CLength / $PageLength)) + 1; //计算页数
$PageArray=array();
$Seperator = array("n","r","。","!","?",";",",","”","'"); //分隔符号
//echo "页数:".$PageCount."<br>";
//echo "长度:".$CLength."<br><br><br>";
//strpos() 函数返回字符串在另一个字符串中第一次出现的位置
if($CLength<$PageLength)
{
echo $content;
}else{
$PageArray[0]=0;
$Pos = 0;
$i=0;
//第一页
for($j=0;$j<sizeof($Seperator);$j++)
{
//echo $Seperator[$j];
$Pos=strpos($content,$Seperator[$j],$PageArray[$i]+1900);
while($Pos > 0 && $Pos < ($i+1)*$PageLength && $Pos > $i*$PageLength )
{
$PageArray[$i] = $Pos ;
$Pos = strpos($Pos+$PageLength,$content,$Seperator[$j]) ;
}
if($PageArray[$i]>0)
{
$j = $j + sizeof($Seperator) + 1;
}
}
//---
for($i=1;$i<$PageCount-1;$i++){
for($j=0;$j<sizeof($Seperator);$j++)
{
//echo $Seperator[$j];
$Pos=strpos($content,$Seperator[$j],$PageArray[$i-1]+1900);
while($Pos > 0 && $Pos < ($i+1)*$PageLength && $Pos > $i*$PageLength )
{
$PageArray[$i] = $Pos ;
$Pos = strpos($Pos+$PageLength,$content,$Seperator[$j]) ;
}
if($PageArray[$i]>0)
{
$j = $j + sizeof($Seperator) + 1;
}
}
}

//--最后一页
$PageArray[$PageCount-1]=$CLength;
//$page=2;
if($page==1)
{
$output=substr($content,0,$PageArray[$page-1]+2);
}
if($page>1 && $page<=$PageCount)
{
$output=substr($content,$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);
$output=" (上接第".($page-1)."页)n".$output;
}
echo str_replace("n","<br> ",$output);
//if($page==$PageCount)
//return $output=substr($content,$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);
if($PageCount>1)
{
echo "<br><br><br><center>";
echo "<font color='ff0000'>".$page."</font>/".$PageCount." 页 ";
if($page>1)
echo "<a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一页</a> ";
else
echo "上一页 ";
for($i=1;$i<=$PageCount;$i++)
{
echo "<a href=$PHP_SELF?expert_id=$expert_id&page_t=".$i.">[".$i."]</a> ";
}
if($page<$PageCount)
echo " <a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page+1).">下一页</a> ";
else
echo " 下一页 ";
echo "</center>";
}
}
}?>

<?php
$content1=''测试文字,尽量长一些,www.111cn.net";
$current=$_REQUEST['page_t'];
$result=ff_page($content1,$current);
echo $result;
?>

php 域名转发程序是我从其它地方看到了,通过xml与php交换实现的,下面我们来看看源文件吧。

<?xml version="1.0" encoding="utf-8"?>
<urls>
 <num>1</num>
 <url id="1">
  <domain>test.domain.com</domain>
  <to>http://www.111cn.net/to>
 </url>
</urls>

index.php文件。

<?php
/*
域名伪跳转方案
By IVershuo.cn
*/
 header("content-type:text/html; charset=utf-8");
 $xml = simplexml_load_file("url.xml"); //xml文件路径
 $to = 'http://www.111cn.net'; //默认跳转地址
 foreach ($xml as $key => $value) {
  if($value->domain == $_SERVER['SERVER_NAME']) {
   $to = $value->to;
   break;
  }
 }
 header('Location: '.$to);
?>

处理文件

<?php
/*
域名伪跳转方案,域名跳转配置脚本
###注意:没设置验证可配置,使用时请修改该文件名和xml文件名!!!
By IVershuo.cn
*/
$xmlFile = 'url.xml'; //xml文件的路径

$xml = simplexml_load_file($xmlFile); 
$num = $xml->num[0];

if (@$_POST['domain'] && $_POST['to']) { 
 $xmlUrl = $xml->addChild('url');
 $xmlUrl->addAttribute('id',$num+=1);
 $xmlUrl->addChild('domain',$_POST['domain']);
 $xmlUrl->addChild('to',$_POST['to']);
 $xml->num[0] = $num;
}

if (@$_GET['del']) {
 removeNode($xml, "//url[@id='".$_GET['del']."']", 'all');
 $xml->num[0] = $num;
}

$sp = fopen($xmlFile,"wb");
fwrite($sp,$xml->asXML());
fclose($sp);

function removeNode($xml, $path, $multi='one'){
       $result = $xml->xpath($path);               
          # for wrong $path
          if (!isset($result[0])) return false;       
          switch ($multi) {
              case 'all':
                    $errlevel = error_reporting(E_ALL & ~E_WARNING);
                    foreach ($result as $r) unset ($r[0]);
                    error_reporting($errlevel);
                    return true;                  
                case 'child':
                   unset($result[0][0]);
                   return true;               
                case 'one':
                   if (count($result[0]->children())==0 && count($result)==1) {
                       unset($result[0][0]);
                       return true;
                   }                 
                default:
           return false;           
          }
}

echo '<?xml version="1.0" encoding="utf-8"?>'."n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>域名添加</title>
<meta name="author" content="阿肆|IVershuo.cn" />
<style type="text/css">
label {display:block;margin:10px 0;}
input {width:300px;}
label span {color:#666;}
</style>
<script type="text/javascript" src=""></script>
</head>
<body>
 <h1>域名转向添加</h1>
 <div>
  <form action="<?=$_SERVER ['PHP_SELF']?>" method="post">  
   <fieldset>
   <legend>域名添加</legend>
    <label for="domain">
     域名:
     http://<input type="text" name="domain" id="domain" />
     <span>不用加“http://”</span>
    </label>
    <label for="to">
     转向:
     <input type="text" name="to" id="to" value="http://" />
     <span>前面添加“http://”或“https://”等</span>
    </label>
    <button type="submit">提交</button>
   </fieldset>
  </form>
 </div>
 <div>
  <ul id="listed">
<?php
 $i=0;
 foreach ($xml as $key => $value) {  
  if($key == 'url') {   
   echo '<li><em>http://'.$value->domain.'</em>跳转到<a href="'.$value->to.'">'.$value->to.'</a>&nbsp;<a href="'.$_SERVER ['PHP_SELF'].'?del='.$xml->url[$i]['id'].'">&gt;删除&lt;</a></li>';
   $i++;
  }
 }
?>
<script type="text/javascript">
 var li=document.getElementById('listed').getElementsByTagName('li');
 for (var i=0,l=li.length;i<l ;i++ ) {
  li[i].getElementsByTagName('a')[1].onclick=function () {
   var u = this.parentNode.getElementsByTagName('em')[0].innerHTML;
   if (confirm ('确定要删除 '+u+' 的转向?')) {
    return true;
   } else {
    return false;
   }
  }
 }
</script>
  </ul>
 </div>
 </body>
</html>


<?php
/**
*通过phpmailer发送qq邮件
*@author ray
*@since 2009-08-07
*/
define('__DEBUG__', false);
define('__PSW_FILE__', dirname(__FILE__) . '/smtp.dat');
define('SLEEPING_EMAIL', dirname(__FILE__) . "/sleepMail.dat");//休眠的email
define('SLEEPING_TIME', 1800);//休眠多长时间,以秒为单位
define('FILE_APPEND', 1);
if (!function_exists('file_put_contents')) {
    function file_put_contents($n, $d, $flag = false) {
        $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
        $f = @fopen($n, $mode);
        if ($f === false) {
            return 0;
        } else {
            if (is_array($d)) $d = implode($d);
            $bytesWritten = fwrite($f, $d);
            fclose($f);
            return $bytesWritten;
        }
    }
}
$errorNo = 0;
$errorMsg = '';
$currTime = time();
$unuseMails = array();
//收件人和邮件标题和邮件内容
$to = isset($argv[1]) ? $argv[1] : "" ;
$subject = isset($argv[2]) ? $argv[2] : "";
$mailFile = isset($argv[3]) ? $argv[3] : "" ;
if (__DEBUG__) {
    echo "
file:$mailFile to:$to subject:$subjectrn";
}
if (empty($mailFile) || empty($to) || empty($subject)) {
    $errorNo = 1;
    $errorMsg = "参数不全";
}
//加载不可用的email列表
if (!$errorNo) {
    if (file_exists(SLEEPING_EMAIL)) {
        $sleepMails = file(SLEEPING_EMAIL);
        if (!empty($sleepMails)) {
       
            foreach($sleepMails as $sleepMail) {
                //解析
                if (false !== strpos($sleepMail, '|')) {
                    $tmp = explode('|', $sleepMail);
                    if (isset($tmp[0]) && isset($tmp[1])) {
                        $mail = trim($tmp[0]);
                        $time = trim($tmp[1]);
                       
                        //是否可用
                        if ( ($currTime - $time )< SLEEPING_TIME) {
                            $unuseMails[] = $mail;
                        }
                    }
                }
            }
        }
    }
}
if (!$errorNo) {
    //随机加载smtp服务器和smtp用户名和密码
    $info = file(__PSW_FILE__);
    $len = count($info);
   
    do {
        $rnd = mt_rand(0, $len - 1);
        $line = isset($info[$rnd]) ? $info[$rnd] : "";
       
        if (false !== strpos($line, '|')) {
       
            $tmp = explode('|', $line);
            if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) {
               
                $smtpServer = trim($tmp[0]);
                $fromMail = trim($tmp[1]);
                $psw = trim($tmp[2]);
                $smtpUserName = substr($fromMail, 0, strrpos($fromMail, '@'));
            }
        }
    }while (in_array($fromMail, $unuseMails));//如果在不可用的列表中,在次加载
   
    if (!isset($smtpServer) || !isset($fromMail) || !isset($psw)) {
        $errorNo = 2;
        $errorMsg = "没找到发件人QQ信箱和密码";
    }
}
if (!$errorNo && __DEBUG__) {
    echo "smtp:$smtpServer from:$fromMail psw:$psw user:$smtpUserNamern";
}
if (!$errorNo) {
    //通过phpmailer连接smtp服务器发信
    require(dirname(__FILE__) . "/phpmailer/class.phpmailer.php");
    require(dirname(__FILE__) . "/phpmailer/class.smtp.php");
    $mail = new PHPMailer();
   
    $body = $mail->getFile($mailFile);
    $body = eregi_replace("[]",'',$body);
   
    //charset
    $mail->CharSet = "GB2312";
   
    //$mail->SMTPDebug = 2;//用于显示具体的smtp错误
   
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    if ("smtp.qq.com" == trim($smtpServer)) {
        $mail->Username = $fromMail;
    } else {
        $mail->Username = $smtpUserName;
    }
    $mail->Password = $psw;
    $mail->Host = $smtpServer;
   
    $mail->From = $fromMail;
    $mail->FromName = "晴天网络";
   
    $mail->IsHTML(true);
   
    $mail->AddAddress($to);
    $mail->Subject = $subject;
    $mail->Body = $body;
   
    if (!$mail->Send()) {
   
       // echo "Message could not be sent. ";
        $errorNo = 3;
        $errorMsg = $mail->ErrorInfo;
    } else {
        echo "
Send to $to success use $fromMailrn";
        exit;
    }
}
if (3 == $errorNo) {
    //记录信息,该信息地址休眠N分钟
    $content = "$fromMail|" . time() . "rn";//email|当前时间戳
    file_put_contents(SLEEPING_EMAIL, $content, FILE_APPEND);
}
echo "
Error No($errorNo) " . $errorMsg . "rn";
exit;
?>

define('IN_UCHOME','asdfasdf');
// 加载dzhome的基本配置文件
include .'/home/data/data_config.php';
// 生成防伪
$action_login    = md5('login'.md5($_SCONFIG['sitekey']));
$action_register = md5('register'.md5($_SCONFIG['sitekey']));
$action_formhash = substr(md5(substr(time(), 0, -7).'|0|'.md5($_SCONFIG['sitekey']).'|'.$hashadd), 8, 8);
echo '
<script>
var  loginNum    = "',($action_login    = md5('login'.md5($_SCONFIG['sitekey']))),'";
var  registerNum = "',($action_register = md5('register'.md5($_SCONFIG['sitekey']))),'";
var  formhashNum = "',($action_formhash = substr(md5(substr(time(), 0, -7).'|0|'.md5($_SCONFIG['sitekey']).'|'.$hashadd), 8, 8)),'"
</script>
<ul class="login">
<form  name="loginform" action="/home/do.php?ac=',$action_login,'&&ref" method="post">
<input type="text" name="username" size="10" value="用户名">
<input type="text" name="password" size="9" value="密码">
<input type="hidden" name="refer" value="space.php?do=home" />
<input type="hidden" name="formhash" value="',$action_formhash,'">
<input type="submit" value="登陆" class="int" name="loginsubmit">
<input type="button" name="regbutton" class="int" value="注册" class="button">
<input type="button"  value="忘记密码" class="int"  >
</ul>
</form>

<?php

$count = 0;

while(true) {

    system('ping qq.com', $retval);

 if(!$retval) {

  break;

 } else {

  $count ++;

 }

 if($count > 10) {

     system('shutdown -s -t 60 -f -c "网络不通,60s后关机"', $retval);

 }

}

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
  • PHP函数strip_tags的一个bug浅析

    PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数...2014-05-31
  • SQL Server中row_number函数的常见用法示例详解

    这篇文章主要给大家介绍了关于SQL Server中row_number函数的常见用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
  • PHP加密解密函数详解

    分享一个PHP加密解密的函数,此函数实现了对部分变量值的加密的功能。 加密代码如下: /* *功能:对字符串进行加密处理 *参数一:需要加密的内容 *参数二:密钥 */ function passport_encrypt($str,$key){ //加密函数 srand(...2015-10-30