PHP伪静态步骤

<?php 
    header("content-type:text/html;charset=utf-8");
    $dsn = "mysql:host=localhost;dbname=seven";
    $db = new PDO($dsn, 'root', '');
    $db->exec("set names utf8");
    //分页
    $count=11;
    $page_size=3;
    //总页数除以每页的条数,算出有几页。
    $page_count=ceil($count/$page_size);
    $page=empty($_GET['id'])?1:intval($_GET['id']);
    $limit=($page-1)*$page_size;
    $sql="select * from ai limit $limit,$page_size";
    // var_dump($sql);die;
    $rs = $db->query($sql);
    $arr = $rs->fetchAll(PDO::FETCH_ASSOC);

    //var_dump($arr);die;


    $xxx= new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><ccc></ccc>');
    $p=$xxx->addChild('p');
    foreach ($aa as $key => $val) {
          foreach ($val as $k => $v) {
              $p->addChild($v);
          }
    }
    // var_dump($p);die;

    $xxx->asXML('66.xml');

?>

<center>
   <body style="background-image:url(19099.jpg)">
  <table>
  <tr>
  <td>ID</td>
  <td>尊姓大名</td>
  <td>人物详情</td>
  </tr>
   <?php foreach ($arr as $key => $value) { ?>
  <tr>
  <td><?php echo $value['id']?></td>
  <td><?php echo $value['name']?></td>
  <td><?php echo $value['xiangqing']?></td>
  </tr>
  <?php } ?>
<?php 
          //page是当前页
         if($page-1<=0){
          $up=1;
         }else{
          $up=$page-1;
         }
         if($page+1>=$page_count){
          $next=$page_count;
         }else{
          $next=$page+1;
         }
 ?>
    <a href="show_<?=$id=1?>.html">shou页</a>
     <a href="show_<?=$up?>.html">上一页</a>
     <a href="show_<?=$next?>.html">下一页</a>
     <a href="show_<?= $page_count?>.html">wei页</a>
  </table>
 </center>
    </body>
 <?php
file_put_contents($page.'.html',ob_get_contents());
ob_end_flush();
?> 


加入伪静态规则。

RewriteEngine on
RewriteRule (.*)_(\d).html$ $1.php?id=$2
RewriteRule (.*)\.html$ $1.php


伪静态效果,成功后悔有一个xml文件产生



猜你喜欢

转载自blog.csdn.net/qq_39618374/article/details/78827200