设为首页 收藏本站
查看: 450|回复: 0

[经验分享] php生成html分页方法-----ob篇

[复制链接]

尚未签到

发表于 2017-4-4 13:45:55 | 显示全部楼层 |阅读模式
  效果图如下:
  第一页: DSC0000.jpg
  第二页:
DSC0001.jpg

  实现方法如下:
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><?global $start; require('../include/common.ini');require('../class/mysql.class.php');require('../class/page.class.php');require('../fun/fun_pinyin.php');$db =new mysql_db;$db->sql_connect($db_host,$db_username,$db_userpass,$db_database);$onepage =5;$sql = "select id from successpic";$query =$db->query($sql);$num = $db->get_num_rows($query);$allpages = ceil ($num / $onepage);
  for ($x = 0;$x<$allpages; $x++){
  for ($y = 0;$y<$allpages; $y++){if ($y == 0){$list1 .= '<a href="indexp.html" >第'.$y.'页 </a>|';} else {$list1 .= "<a href='index_".$y.".html' >第".$y."页 </a>|";}}
  $start = $x * $onepage;
  $sql1 = "select * from successpic order by id desc limit $start,$onepage";//$start=null;$result1=$db->query($sql1);$tupian=$db->get_num_rows($result1);
  while($row=$db->fetch_row($result1)){ $title[$x][]=$row['title'];$address[$x][]=$row['address'];$psrc[$x][]=$row['psrc'];$content[$x][]=$row['content'];}$result1=null;$row=null;ob_start();
  ?><?
  ?> <script language="JavaScript"> <!-- //图片按比例缩放 var flag=false; function DrawImage(ImgD){ var image=new Image(); var iwidth = 150; //定义允许图片宽度 var iheight = 150; //定义允许图片高度 image.src=ImgD.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>= iwidth/iheight){ if(image.width>iwidth){ ImgD.width=iwidth; ImgD.height=(image.height*iwidth)/image.width; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } else{ if(image.height>iheight){ ImgD.height=iheight; ImgD.width=(image.width*iheight)/image.height; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } } } //--> </script><!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><link href="../html/images/css/style.css" rel="stylesheet" type="text/css" /></head>
  <body><table width="1007" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="767" height="3" bgcolor="#000000"></td><td width="172" height="3" bgcolor="#CCCCCC"></td><td width="68" height="3" bgcolor="#000000"></td></tr></table><table width="1007" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="251" align="right"><a href="index.html"><img src="../html/images/logo.jpg" width="185" height="97" border="0" /></a></td><td width="1" align="center" bgcolor="E7E7E7">&nbsp;</td><td width="687"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="51" valign="top"><div id="s1">加入收藏   设为首页</div></td></tr><tr><td height="46"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="687" height="46"><param name="movie" value="../html/images/flash/menu.swf" /><param name="quality" value="high" /><embed src="../html/images/flash/menu.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="687" height="46"></embed></object></td></tr></table></td><td width="68" class="bj">&nbsp;</td></tr></table><table width="1007" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="1" bgcolor="#E7E7E7"></td></tr><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1007" height="251"><param name="movie" value="../html/images/flash/4.swf" /><param name="quality" value="high" /><embed src="../html/images/flash/4.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1007" height="251"></embed></object></td></tr></table><table width="1007" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="252" align="right" valign="top"><table width="174" border="0" cellspacing="0" cellpadding="0"><tr><td width="1" bgcolor="#CCCCCC"></td><td width="172" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="../html/images/anli.jpg" width="172" height="79" /></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr  onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl"><td height="30" align="left" class="font4"><a href="<?=Pinyin('典型用户',1).'.html'?>">典型用户</a></td></tr><tr ><td height="1" align="left" bgcolor="#E3E3E3"></td></tr><tr  onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl"><td height="30" align="left" class="font4"><a href="indexp.html">相关合影</a></td></tr><tr ><td height="1" align="left" bgcolor="#E3E3E3"></td></tr><tr  onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl"><td height="30" align="left" class="font4"><a href="#"></a></td></tr><tr ><td height="1" align="left" bgcolor="#E3E3E3"></td></tr><tr  onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl"><td height="30" align="left" class="font4"><a href="#"></a></td></tr><tr ><td height="1" align="left" bgcolor="#E3E3E3"></td></tr></table><table width="100%" border="0" cellspacing="5" cellpadding="3">
  <tr><td align="center"><img src="../html/images/index2_r9_c3.gif" width="152" height="36" /></td></tr><tr><td align="center"><img src="../html/images/index2_r11_c3.gif" width="152" height="37" /></td></tr><tr><td align="center"><img src="../html/images/index2_r13_c3.gif" width="152" height="37" /></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="bottom"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="bj1"><tr><td height="30">&nbsp;</td></tr></table></td></tr><tr><td><table width="96%" border="0" cellspacing="5" cellpadding="3"><tr><td align="left"><span class="font">售后热线 0731-5078995<br />销售热线 0731-5078877<br /></span>客户投诉 0731-5078995<br />传 真 0731-5078995<br />E-mail: jswkj@jswkj.com<br />地 址:湖南长沙市五一<br />路105号(比云天大厦)</td></tr></table></td></tr></table></td><td width="1" height="1000" bgcolor="#CCCCCC"></td></tr></table></td><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="686" valign="top" class="bj2"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="73%">&nbsp;</td><td width="27%" height="50"><a href="index.html">首页</a> &gt;&gt; 成功案例 &gt;&gt; <span class="font">相关合影</span></td></tr></table><table width="96%" border="0" align="center" cellpadding="0" cellspacing="5" class="bk7"><tr><td><span class="font02">金思维的理念和综旨</span><br />金思维不断的 吸收新知和创新,关注与客户长期的相互支持与合作,打破传统的 销售服务理念,为每一个客户量身定制跟踪的技术服务方案,始终 坚持用户的成功和满意,是我们长远发展的强有力保障。 </td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>&nbsp;</td></tr><tr><td height="1" bgcolor="#E1E1E1"></td></tr></table><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>&nbsp;</td></tr><tr><td height="40" class="font9">相关合影</td></tr><tr><td><table width="100%" border="0" cellpadding="0" cellspacing="2" bgcolor="#BD6A0E"><tr><td width="12%" height="3"></td><td width="88%" height="3" bgcolor="#FFFFFF"></td></tr></table></td></tr></table><!-----------------图片列表显示-----------------------------> <table width="96%" border="0" align="center" cellpadding="0" cellspacing="8"><?for($i=0;$i<=$tupian;$i++){echo "<tr>";for($j=$i;$j<=$i+3;$j++){if ($j>$tupian-1) {  break;
  }else{echo "<td align='center'><A href='../".$psrc[$x][$j]."' title='".$title[$x][$j]."'><img src='".$address[$x][$j]."' onload = 'DrawImage(this)' border=0 alt='".$title[$x][$j]."'/><br>".$title[$x][$j]."</a><br> $j </td>";}}echo"</tr>";$i=$i+3;//echo "<br>";}?><div><?
  echo $list1;
  $list1=null; ?> </div></table></td><td width="1" height="520" bgcolor="#E7E7E7"></td></tr></table> </td><td width="68" class="bj">&nbsp;</td></tr></table><table width="1007" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="75" height="1" bgcolor="#CCCCCC"></td><td width="160" height="1"></td><td width="716" height="1" bgcolor="#CCCCCC"></td></tr></table><table width="900" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="18"></td></tr></table><table width="1007" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="1" colspan="7" bgcolor="#CCCCCC"></td></tr><tr><td width="78" bgcolor="#F6F6F6"></td><td width="1" bgcolor="#CCCCCC"></td><td width="172" height="80" bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="17%" align="center"><img src="../html/images/ico9.gif" width="5" height="5" /></td><td width="83%">友情连接</td></tr><tr><td colspan="2" align="center"><select name="select"><option>----------------</option></select> </td></tr></table></td><td width="1" bgcolor="#CCCCCC"></td><td width="680" align="center" bgcolor="#FFFFFF"><span class="font1">版权所有:长沙新友软件开发有限公司 <br />地址:长沙市解放东路38号华瑞电子大厦B座1805室(赛博数码广场北栋) <br />在线咨询QQ:200873178 总机:0731-2919501 2919502 2919503 2919506 </span><br /></td><td width="1" bgcolor="#CCCCCC"></td><td width="65" bgcolor="#F6F6F6"></td></tr></table></body></html>
  <?$temp = ob_get_contents();
  ob_end_clean();if ($x == 0){$indexpath = "../news/indexp.html";} else {$indexpath = "../news/index_".$x.".html";}
  $title[]=null;$address[]=null;$psrc[]=null;$content[]=null;
  if (is_file ($indexpath)){@unlink ($indexpath); //若文件已存在,则删除}$handle = fopen ($indexpath,"w"); //打开文件指针,创建文件/*  检查文件是否被创建且可写*/if (!is_writable ($indexpath)){echo "文件:".$indexpath."不可写,请检查其属性后重试!"; //修改为echo}if (!fwrite ($handle,$temp)){ //将信息写入文件echo "生成文件".$indexpath."失败!"; //修改为echo} fclose ($handle); //关闭指针$temp=null;
  }echo("<script>alert('成功生成静态文件!');history.go(-1);</script>");?>
  上面为整个页面的代码:
  主要是用ob来控制html文件源代码的获取,然后通过基本文件操作来实现html文件生成.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-360141-1-1.html 上篇帖子: php mail() 防止垃圾邮件 How to Avoid Spam Filters with PHP mail() Emails 下篇帖子: 用php实现简单的图片组合(合成)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表