php 新闻文章分页代码实例教程

 更新时间:2016年11月25日 15:57  点击:2124

unction explode_content($content, $length) { 

02 $i = 0; 

03 $k = 1; 

04 $j = 0; 

05 $wn = 0; 

06 $s = ''; 

07 $e = 1; 

08 $yh = 0; 

09 while ($k) { 

10 $d = $content[$i]; 

11 if ($d !== '') { 

12 if (ord($d) > 127) { 

13 $j++; 

14 $num = 2; 

15 $i++; 

16 } else { 

17 $num = 1; 

18 } 

19 $j++; 

20 } else { 

21 if ($s) { 

22 $listdb[] = addslashes($s); 

23 } 

24 $k = 0; 

25 } 

26 $v1 = $j - $num; 

27 $w = substr($content, $v1, $num); 

28 if ($w !== '') { 

29   

30 if ($w == '<') { 

31 $e = 0; 

32 } 

33 if (!$e && $w == '"') { 

34 $yh++; 

35 } 

36 if ($e && $w != ' ' && $w != ' ') { 

37 $wn++; 

38 } 

39 if ($w == '>' && $yh % 2 == 0) { 

40 $e = 1; 

41 } 

42 $s .= $w; 

43 } 

44 if ($wn >= $length && $e) { 

45 $listdb[] = addslashes($s); 

46 $s = ''; 

47 $wn = 0; 

48 } 

49 $i++; 

50 } 

51 return $listdb; 

52 } 

53   

54   

55   

56 分页使用 

57 $page_per = 500; //每页字数 
php文章内容分页
58 $article_list = explode_content($article, $page_per); //拆分文章 

59 $page_count = count($article_list); 

60 $page = !empty($_GET['page']) ? intval($_GET['page']) : 1; 

61 $page = ($page > $page_count && $page_count>0) ? $page_count : $page; 

62 $article = strips教程lashes($article_list[$page -1]); 

63 if ($page_count>1) { 

64 if ($page == 1) { 

65 $page_code = "<a href="news.php?id=$id&page=".($page+1)."">下页</a> <a href="news.php?id=$id&page=$page_count">末页</a> "; 

66 } 

67 elseif ($page == $page_count) { 

68 $page_code = "<a href="news.php?id=$id&page=".($page-1)."">上页</a> <a href="news.php?id=$id&page=1">首页</a> "; 

69 } else { 

70 $page_code = "<a href="news.php?id=$id&page=".($page+1)."">下页</a> <a href="news.php?id=$id&page=".($page-1)."">上页</a> "; 

71 } 

72 }

class HttpRequest
{
var $sHostAdd;
var $sUri;
var $iPort;

var $sRequestHeader;

var $sResponse;

function HttpRequest($sUrl){
$sPatternUrlPart = '/http://([a-z-.0-9]+)(:(d+)){0,1}(.*)/i';
$arMatchUrlPart = array();
preg_match($sPatternUrlPart, $sUrl, $arMatchUrlPart);

$this->sHostAdd = gethostbyname($arMatchUrlPart[1]);
if (empty($arMatchUrlPart[4])){
$this->sUri = '/';
}else{
$this->sUri = $arMatchUrlPart[4];
}
if (empty($arMatchUrlPart[3])){
$this->iPort = 80;
}else{
$this->iPort = $arMatchUrlPart[3];
}

$this->addRequestHeader('Host: '.$arMatchUrlPart[1]);
$this->addRequestHeader('Connection: Close');
}

function addRequestHeader($sHeader){
$this->sRequestHeader .= trim($sHeader)." ";
}

function sendRequest($sMethod = 'GET', $sPostData = ''){
$sRequest = $sMethod." ".$this->sUri." HTTP/1.1 ";
$sRequest .= $this->sRequestHeader;
if ($sMethod == 'POST'){
$sRequest .= "Content-Type: application/x-www-form-urlencoded ";
$sRequest .= "Content-Length: ".strlen($sPostData)." ";
$sRequest .= " ";
$sRequest .= $sPostData." ";
}
$sRequest .= " ";

$sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$sockHttp){
die('socket_create() failed!');
}

$resSockHttp = socket_connect($sockHttp, $this->sHostAdd, $this->iPort);
if (!$resSockHttp){
die('socket_connect() failed!');
}

socket_write($sockHttp, $sRequest, strlen($sRequest));

$this->sResponse = '';
while ($sRead = socket_read($sockHttp, 4096)){
$this->sResponse .= $sRead;
}

socket_close($sockHttp);
}

function getResponse(){
return $this->sResponse;
}

function getResponseBody(){
$sPatternSeperate = '/ /';
$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);
return $arMatchResponsePart[1];
}

function getResponseHead(){
$sPatternSeperate = '/ /';
$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);
return $arMatchResponsePart[0];
}
}

标签是给Smarty的指令符,以模板定界符包住。这些指令符可以是变量,以$符号代表函数、逻辑 或 流程控制 语法。Smarty 允许 PHP 程式设计师以Smarty 标签去定义可存取的函数

smarty 模板if else使用实例与入门教程
smarty 主要功能是完成美工与程序分离,并且使用的缓存技术,减轻服务器的负载,
smarty 以在文件中放置特殊的“Smarty标签”来产生网页内容。这些标签会被处理并替换成其他的内容。

 

*/

require('smarty/libs/Smarty.class.php教程');

$tpl = new Smarty();
$tpl->template_dir   = 'd/'
$tpl->compile_dir    = 'd/template_c';

$tpl->compile_check   = false;//$cfg['debug'];
$tpl->debugging      = false;
$tpl->caching       = false;
$tpl->cache_lifetime  = 3600;

$tpl->left_delimiter  = '<!--{';
$tpl->right_delimiter  = '}-->';

$array = 'www.111cn.net'
$tpl->assign('dataList', $array);
$tpl->display('a.tpl');

/*
a.tpl
<!--{if $dataList =='www.111cn.net'}-->
 <!--{$dataList}-->
<!--{else}-->
 echo 'aaa';
<!--{/if}-->

还有另一种方法

{if $name eq 'Fred'}
    Welcome Sir.
{elseif $name eq 'Wilma'}
    Welcome Ma'am.
{else}
    Welcome, whatever you are.
{/if}

{* an example with "or" logic *}
{if $name eq 'Fred' or $name eq 'Wilma'}
   ...
{/if}

本文章原创于www.111cn.net转载注明出处

修改dedecms 织梦系统 生成静态页面栏目缓存文件路径
由于dedecms 生成频道栏目,要生成一个临时mkall_cache_{adminid}.php教程文件,这对网站做安全会有一定的影响,特别我现在是把我整个网站限制不能上传php,js文件,为了方便起见,今天我就来拿我修改过程记录下来与各位分享吧。
首页我们找到dedecms  的后台管理上当默认是在dede/目录。

找到文件:
makehtml_all.php
找到73行,

//$mkcachefile = DEDEROOT."/data/mkall_cache_{$adminID}.php";
改成你的站外目录如
$mkcachefile = "s:/s/data/mkall_cache_{$adminID}.php";

这是要写缓存文件的,就是把你更新的目录ID保存到一个数组里

再找到147行

//$mkcachefile = DEDEDATA."/mkall_cache_{$adminID}.php";
$mkcachefile = "s:/s/data/mkall_cache_{$adminID}.php";

好了,保存文件,我们再在当前上当找到

makehtml_list_action.php

找到第37行
//$mkcachefile = DEDEROOT."/data/mkall_cache_{$adminID}.php";
$mkcachefile = "s:/s/data/mkall_cache_{$adminID}.php";

保存上传就OK了。

本文章原创于www.111cn.net 转载注明出处

<?php教程
class resizeimage
{
    //图片类型
    var $type;
    //实际宽度
    var $width;
    //实际高度
    var $height;
    //改变后的宽度
    var $resize_width;
    //改变后的高度
    var $resize_height;
    //是否裁图
    var $cut;
    //源图象
    var $srcimg;
    //目标图象地址
    var $dstimg;
    //临时创建的图象
    var $im;
    function resizeimage($img, $wid, $hei,$c,$dstpath)
    {
        $this->srcimg = $img;
        $this->resize_width = $wid;
        $this->resize_height = $hei;
        $this->cut = $c;
        //图片的类型
        $this->type = strtolower(substr(strrchr($this->srcimg,"."),1));
        //初始化图象
        $this->initi_img();
        //目标图象地址
        $this -> dst_img($dstpath);
        //--
        $this->width = imagesx($this->im);
        $this->height = imagesy($this->im);
        //生成图象
        $this->newimg();
        ImageDestroy ($this->im);
    }
    function newimg()
    {
        //改变后的图象的比例
        $resize_ratio = ($this->resize_width)/($this->resize_height);
        //实际图象的比例
        $ratio = ($this->width)/($this->height);
        if(($this->cut)=="1")
        //裁图
        {
            if($ratio>=$resize_ratio)
            //高度优先
            {
                $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
                imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
                ImageJpeg ($newimg,$this->dstimg);
            }
            if($ratio<$resize_ratio)
            //宽度优先
            {
                $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
                imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio));
                ImageJpeg ($newimg,$this->dstimg);
            }
        }
        else
        //不裁图
        {
            if($ratio>=$resize_ratio)
            {
                $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio);
                imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height);
                ImageJpeg ($newimg,$this->dstimg);
            }
            if($ratio<$resize_ratio)
            {
                $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height);
                imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height);
                ImageJpeg ($newimg,$this->dstimg);
            }
        }
    }
    //初始化图象
    function initi_img()
    {
        if($this->type=="jpg")
        {
            $this->im = imagecreatefromjpeg($this->srcimg);
        }
        if($this->type=="gif")
        {
            $this->im = imagecreatefromgif($this->srcimg);
        }
        if($this->type=="png")
        {
            $this->im = imagecreatefrompng($this->srcimg);
        }
    }
    //图象目标地址
    function dst_img($dstpath)
    {
        $full_length  = strlen($this->srcimg);
        $type_length  = strlen($this->type);
        $name_length  = $full_length-$type_length;
        $name         = substr($this->srcimg,0,$name_length-1);
        $this->dstimg = $dstpath;
//echo $this->dstimg;
    }
}
$resizeimage = new resizeimage("1.jpg", "200", "150", "1","2.jpg");
?>

[!--infotagslink--]

相关文章

  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • JS+CSS实现分类动态选择及移动功能效果代码

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

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
  • vue.js 表格分页ajax 异步加载数据

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

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • 几种延迟加载JS代码的方法加快网页的访问速度

    本文介绍了如何延迟javascript代码的加载,加快网页的访问速度。 当一个网站有很多js代码要加载,js代码放置的位置在一定程度上将会影像网页的加载速度,为了让我们的网页加载速度更快,本文总结了一下几个注意点...2013-10-13
  • php怎么用拼音 简单的php中文转拼音的实现代码

    小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
  • php导出csv格式数据并将数字转换成文本的思路以及代码分享

    php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07