class Shtml
{
var $Templet ;
var $DataSource ;
var $Dir ;
var $fileName ;
var $mod ;
var $handle ;
function Shtml ( $fileName = "" )
{
$this -> fileName = $fileName ;
$this -> mod = " wb " ;
$this -> handle = false ;
$this -> Templet = "" ;
$this -> DataSource = array () ;
$this -> Dir = "" ;
}
// 绑定数据源,参数为一数组
function BindData ( $arr )
{
$this -> DataSource = $arr ;
}
// 设置文件存放路径
function SetDir ( $dir )
{
$this -> Dir = $dir ;
}
function SetFileName ( $fileName )
{
return $this -> fileName = $fileName ;
}
function GetMod ()
{
return $this -> mod ;
}
function SetMod ( $mod )
{
return $this -> mod = $mod ;
}
function Open ()
{
if ( substr ( $this -> fileName , 0 , 1 ) == " / " )
$this -> fileName = $_SERVER [ ' DOCUMENT_ROOT ' ] . $this -> fileName ;
if ( $this -> handle = fopen ( $this -> fileName , $this -> mod ))
return $this -> handle ;
else
return false ;
}
function Close ()
{
return fclose ( $this -> handle ) ;
}
function Write ( $content )
{
return fwrite ( $this -> handle , $content ) ;
}
function MkDir ( $pathname )
{
$currentPath = "" ;
str_replace ( " \\ " , " / " , $pathname ) ;
$pathArr = split ( " / " , $pathname ) ;
if ( $pathArr [ 0 ] == "" ) { //使用绝对路径
$currentPath = $_SERVER [ ' DOCUMENT_ROOT ' ] ;
} else {
$currentPath = $_SERVER [ ' DOCUMENT_ROOT ' ] . dirname ( $_SERVER [ ' PHP_SELF ' ]) ;
}
for ( $i = 0 ; $i if ( $pathArr [ $i ] == "" )
continue ;
else
if ( is_dir ( $currentPath . " / " . $pathArr [ $i ]))
$currentPath = $currentPath . " / " . $pathArr [ $i ] ;
else
mkdir ( $currentPath = $currentPath . " / " . $pathArr [ $i ]) ;
}
}
// 生成静态文件
function Create ()
{
$tmp = $this -> Templet ;
foreach ( $this -> DataSource as $key => $value ) {
$tmp = str_replace ( " " , $value , $tmp ) ;
}
$this -> MkDir ( dirname ( $this -> fileName )) ;
$this -> Open () ;
$this -> Write ( $tmp ) ;
$this -> Close () ;
}
}
function CreateShtml () {
ob_start ( " callback_CteateShtml " ) ;
}
function callback_CteateShtml ( $buffer ) {
$page = intval ( @ $_REQUEST [ " page " ]) ;
$shtml = new Shtml () ;
$shtml -> SetFileName ( $_SERVER [ ' DOCUMENT_ROOT ' ] . dirname ( $_SERVER [ ' PHP_SELF ' ]) . " / " . basename ( $_SERVER [ ' PHP_SELF ' ] , " .php " ) . ( $page == 0 ? "" : " _ " . strval ( $page )) . " .html " ) ;
$shtml -> Templet = $buffer ;
$shtml -> Create () ;
return $buffer ;
}
?>
0
0
相关文章
php后端是什么意思_PHP后端的概念定义与核心作用
如何在 HTML 下拉菜单中实现 PHP 文件的即时跳转
初学者学php会话教程 | 初学者学php会话教程分享
php做后端的坏处_对比其他语言分析PHP的劣势与挑战
php做后端还会有前景吗_剖析PHP在现代开发中的竞争力与未来
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
C++ 高级模板编程与元编程
本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。
10
2026.01.23
Golang 性能分析与pprof调优实战
本专题系统讲解 Golang 应用的性能分析与调优方法,重点覆盖 pprof 的使用方式,包括 CPU、内存、阻塞与 goroutine 分析,火焰图解读,常见性能瓶颈定位思路,以及在真实项目中进行针对性优化的实践技巧。通过案例讲解,帮助开发者掌握 用数据驱动的方式持续提升 Go 程序性能与稳定性。
9
2026.01.22
热门下载
相关下载
精品课程
相关推荐
/
热门推荐
/
最新课程
最新文章








