頁面靜態化

2021-07-22 20:16:05 字數 2540 閱讀 1224

<?php

header("content-type:text/html;charset=utf8");

set_time_limit(0);

$url = "";

$str = file_get_contents($url);

// var_dump($str);die;

$reg = '#.*#isu';

preg_match_all($reg,$str,$arr);

// var_dump($arr);die;view-source:

for ($j=0; $j < count($arr[0]); $j++) else*/

// 匹配標題

$reg_title = '#.*#isu';

preg_match($reg_title,$arr[0][$j],$arr_title);

// var_dump($arr_title);die;

// 匹配內容

$reg_content = '#.*#isu';

preg_match($reg_content,$arr[0][$j],$arr_content);

// var_dump($arr_content);die;

// 匹配時間

$reg_time = '#

(.*)#isu';

preg_match($reg_time,$arr[0][$j],$arr_time);

// 開啟pdo擴充套件

$pdo = new pdo("mysql:host=127.0.0.1;dbname=demo","root","root");

$pdo->exec("set names utf8");

// 將標題 內容 時間    入庫

$arr_title = $arr_title[1];

$arr_content = $arr_content[1];

$arr_time = $arr_time[1];

/*$sql = "insert into ymjth (arr_img,arr_title,arr_content,arr_time) values('$file_name','$arr_title','$arr_content','$arr_time')";

$pdo->exec($sql);*/

//展示

$sum = 80;

$sql_look = "select * from ymjth limit $sum";

$preobj = $pdo->prepare($sql_look);

$preobj->execute(array(20));

$look = $preobj->fetchall(pdo::fetch_assoc);

}//搜尋後分頁

$sou = isset($_request['sou']) ? $_request['sou'] : '';

//分頁(php)

$page = isset($_get['page']) ? $_get['page'] : 1;//當前頁

// echo $page;die;

$counts = count($pdo->query("select * from ymjth where arr_title like '%$sou%'")->fetchall(pdo::fetch_assoc));//總條數

$length = 3;

$pages = ceil($counts/$length);//總頁數

// echo $pages;die;

//頁碼

$offset = ($page-1)*$length;//偏移量

// echo $offset;die;

$data = $pdo->query("select * from ymjth where arr_title like '%$sou%' limit $offset,$length")->fetchall(pdo::fetch_assoc);

// var_dump($data);die;

?>

編號id

標題內容

時間<?php foreach ($data as $key => $value): ?>

<?php echo $value['id'] ?>

<?php echo $value['arr_title'] ?>

<?php echo $value['arr_content'] ?>

<?php echo $value['arr_time'] ?>

<?php endforeach ?>

.html">首頁

_<?php echo urlencode($sou) ?>.html">末頁

#開啟重寫引擎

rewriteengine on

#配置重寫規則

rewriterule  a.html      demo/9.16/2/a.php [l,nc]

#分頁的偽靜態配置

rewriterule  (\d+).html      demo/9.16/2/a.php?page=$1 [l,nc]

頁面靜態化

隨著 的內容的增多和使用者訪問量的增多,無可避免的是 載入會越來越慢,受限於頻寬和伺服器同一時間的請求次數的限制,我們往往需要在此時對我們的 進行 優化和伺服器配置的優化。一般情況下會從以下方面來做優化 什麼是靜態化?純靜態 將php程式生成靜態的html檔案,儲存到伺服器的磁碟中。客戶端訪問的時候...

頁面靜態化

隨著 的內容的增多和使用者訪問量的增多,無可避免的是 載入會越來越慢,受限於頻寬和伺服器同一時間的請求次數的限制,我們往往需要在此時對我們的 進行 優化和伺服器配置的優化。一般情況下會從以下方面來做優化 1.為什麼要靜態化?一 加快頁面開啟瀏覽速度,因為無需連線資料庫 二 有利於搜尋引擎優化seo ...

頁面靜態化

頁面靜態化的作用 1.避免每次訪問都要查詢資料庫的 大量 資料 2.採用主 頁靜態的方式是為 提公升主頁的訪問效率,因為主頁是 訪問量最大的頁面 1.準備主 頁靜態化工具方法 contents.crons.py from collections import ordereddict from dja...