对 HTML 页面地抓取和收录都比动态页面更及时更全面,世界各大搜索引擎例如百度、 Google等。使用静态化 HTML 页面极大地增加网站被搜索到几率。让您有更多地机会展现自己。 以下提供使用PHP来静态化的类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| class Shtml { public function __construct($url, $fileBag, $folderRoot, $folderName, $fileid) { $this->url = $url; $this->fileBag = $fileBag; $this->fileRoot = $folderRoot; $this->fileName = $folderName; $this->fileid = $fileid; Shtml::useFolder (); } public function loadcontent ($folder) { ob_start(); require_once $this->url; Shtml::writehtml ($folder,ob_get_contents()); ob_clean(); } public function usefolder () { if($this->fileBag==1) { $folder=$this->fileName; } else if($this->fileBag==2) { $folder=date('Ymd',time()); } else { exit($this->message1); } if(!is_dir($this->fileRoot.$folder)){ mkdir($this->fileRoot.$folder,0700); } Shtml::loadcontent ($folder); } public function writehtml ($folder,$cache_value) { $file = fopen($this->fileRoot.$folder.'/'.$this->fileid.'.html','w+'); fwrite($file,$cache_value); fclose($file); } } $shtml = new Shtml('http://www.zzlabs.com.cn',1,'','cc',2);
|