有需求联系

Information

- 信息浏览 -

PHP静态生成

2022-10-12 734

方式1

// 获取当前地址
$homedir = 'http://' . $_SERVER['HTTP_HOST'] . '/';
// readfile() 函数读取一个文件,并写入到输出缓冲。
@readfile($homedir . 'index.php?id=0100');
// ob_get_contents得到缓冲区的数据
file_put_contents('index.html', ob_get_contents());
// 函数ob_end_clean会清除缓冲区的内容,并将缓冲区关闭,但不会输出内容。
ob_end_clean();

echo "OK" . $homedir;

方式2

//静态文件夹目录
  $dir="html/".date("Ymd")."/";
  
  if(is_dir($dir)){
    }else {
	 mkdir($dir,0777,true);
	}
  // 内容
  $content123="fasdfsfasdfs11fasdfs222";

   //替换example内容,并获取内容赋值给$str
    $fp=fopen("example.html","r");
    $str=fread($fp,filesize("example.html"));
    $str=str_replace("{title}","title123",$str);
    $str=str_replace("{content}",$content123,$str);
    fclose($fp);
   
      $wj=$dir."abc.html";
      $handle = fopen($wj,"w");
      fwrite($handle, $str);
      fclose($handle);


Copyright © 2024 镇江小蚂蚁信息科技有限公司 All Rights Reserved.