静态页面生成之方案
随着网络的发展,SEO逐渐得到了我们的重视,把网站做成静态网站是势在必行了.生成静态页面的方法不外乎几种,看了很多资料,都是介绍通过OB函数控制输出的,我在这里给大家介绍我的方法: 通过file_get_contents()方法.这个方法可以获取网页的内容,包括本地的和internet上的,所以我们可以通过$content = file_get_contents("http://localhost/index.php");获取本地的或者防在服务器上的文件输出结果,然后创建指定的目录和文件,最后把内容写进去,从而实现了静态页面的输出.在这里,我发两个函数,一个是写函数,一个是读函数.完全兼容php4和php5.function dfile_put_contents($file, &$data, $flags=0){
// Check to see if functin exists
if (function_exists('file_put_contents')) {
file_put_contents($file, $data);
}else{
// Define constants used by function, if not defined
if (!defined('FILE_USE_INCLUDE_PATH')) define('FILE_USE_INCLUDE_PATH', 1);
if (!defined('FILE_APPEND')) define('FILE_APPEND', 8);
// Varify arguments are correct types
if (!is_string($file)) return(false);
if (!is_string($data) && !is_array($data)) return(false);
if (!is_int($flags)) return(false);
// Set the include path and mode for fopen
$include = false;
$mode = 'wb';
// If data in array type..
if (is_array($data)) {
// Make sure it's not multi-dimensional
reset($data);
while (list(, $value) = each($data)) {
if (is_array($value)) return(false);
}
unset($value);
reset($data);
// Join the contents
$data = implode('', $data);
}
// Check for flags..
// If include path flag givin, set include path
if ($flags&FILE_USE_INCLUDE_PATH) $include = true;
// If append flag givin, set append mode
if ($flags&FILE_APPEND) $mode = 'ab';
// Open the file with givin options
if (!$handle = @fopen($file, $mode, $include)) return(false);
// Write data to file
if (($bytes = fwrite($handle, $data)) === false) return(false);
// Close file
fclose($handle);
// Return number of bytes written
return($bytes);
}
}
function dfile_get_contents($file, $include=false){
// Check to see if functin exists
if (function_exists('file_get_contents')) {
return @file_get_contents($file);
}else{
// Varify arguments are correct types
if (!is_string($file)) return(false);
if (!is_bool($include)) return(false);
// Open the file with givin options
if (!$handle = @fopen($file, 'rb', $include)) return(false);
// Read data from file
$contents = fread($handle, filesize($file));
// Close file
fclose($handle);
// Return contents of file
return($contents);
}
} 路过看看~~ 用ob函数会不会更简单一点呢? 力荐OB. 用了,还可以 也许OB更快些,你这个只是单纯生成了一个文件. 似乎没什么技术可研. 其中的技术就是把file_get_contents和file_put_contents重写了一遍。
自从到了2008年。应该是全世界都用上了PHP5了吧。
所以……这两个写不写都没有什么区别了 链接地址修改了吗? 如果链接地址还是php的, 那这样静态化只是会提高点访问速度,对seo没什么影响
楼主再继再励!!!
写个类似write的规则,然后file_put_contents时替换url,遍历全站php生成静态,太妙了 页面缓冲吧 研究研究 恩 用替换函数 很简单! 使用一个字符串替换字符串中的另一些字符str_replace(find,replace,string,count)
mysql db table 建立 make_number 和maked_html_url 两个字段
再来个 order by id desc 搞定 简单的很! 学习了 恩 学习啦!!!! 如果打开了php的安全控制呢。。。。悲剧。。。。file_get_content(ur)需要php.ini中设置fopen_url支持。。。。。
如果放到我服务器上,这样写的后果就是茶几上的器皿。。。全是怀具了。
页:
[1]