<?
class Shtml
{
var $message1="Error 1: You write class Shtml is Wrong ! The second parameter is 1 or 2 in this class!.";
var $message2="Error 2: The file write Error.";
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);
}
}
$fileid=2;
$shtml = new Shtml("http://www.hzwz.net",1,"cc","",$fileid);
?>
在网上看到的一个生成html的一个累 请问这个类怎么样啊 $shtml = new Shtml("http://www.hzwz.net",1,"cc","",$fileid); 该放在哪个地方? 还有就是ob_get_contents这个函数 得到的是什么内容啊 请高手解答
class Shtml
{
var $message1="Error 1: You write class Shtml is Wrong ! The second parameter is 1 or 2 in this class!.";
var $message2="Error 2: The file write Error.";
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);
}
}
$fileid=2;
$shtml = new Shtml("http://www.hzwz.net",1,"cc","",$fileid);
?>
在网上看到的一个生成html的一个累 请问这个类怎么样啊 $shtml = new Shtml("http://www.hzwz.net",1,"cc","",$fileid); 该放在哪个地方? 还有就是ob_get_contents这个函数 得到的是什么内容啊 请高手解答
解决方案 »
- 请问学习php一年,出来找工作大概能可以开多少的工资?
- 本人在安装php出现了一个问题,请大家指教!
- 请问高手,PHP怎么调用JavaScript函数返回的结果呢?怎么实现JavaScript在服务器端运行?
- 字符串连接,为何说我错了?
- onmouseover 不能用于DIV吗
- 用fpdf生成pdf,怎样将字体嵌入到pdf中??
- PHP有什么好的grid 和 分页插件
- 学 php 面向对象 大家帮帮我!
- 请叫parse error, unexpected T_VARIABLE错误是什么意思啊?
- 附上整个php文件源码,求助修改一个标签的功能
- recordset動態按圖onlcik問題
- file_exists 不支持中文和日文路径
放在类后面,或者在类的调用后面(前面require)
还有就是ob_get_contents这个函数 得到的是什么内容啊 请高手解答缓冲区中的内容
原理就是利用require_once $this->Url; 读取对应URL的内容,然后利用ob_xxx函数将内容写到指定目录的文件里。其实楼主就把他当做一个普通的类来处理就好了,根本不用考虑更多的东西。
<?
class Shtml
{
var $message1="Error 1: You write class Shtml is Wrong ! The second parameter is 1 or 2 in this class!.";
var $message2="Error 2: The file write Error.";
function __construct ($Url,$FileBag,$FolderRoot,$FolderName,$fileid)
{
//读取的URL地址
$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 包含并执行一个对应的URL,不过require_once不支持远程文件。
//个人认为他的意思是说,这个URL对应的文件,必须输出当前内容。
require_once $this->Url;
//用ob_get_contents获取上一个文件输出的内容。然后用writehtml来写入文件。
Shtml::writehtml ($Folder,ob_get_contents());
ob_clean();
}
/********** 指定文件夹*****************/
public function useFolder ()
{
//FileBag为 1的时候指定相关的文件,如果为1的时候,FolderName必须为空,否则在生成静态页面的时候,目录就构造错了。
//为2的时候构造一个以年月日字符串的目录,如果不存在这个目录则建立这个目录。
if($this->FileBag==1)
{
$Folder=$this->FileName;
}
else if($this->FileBag==2)
{
$Folder=date('Ymd',time());
} 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);
}
}
$fileid=2;
$shtml = new Shtml("http://www.hzwz.net",1,"cc","",$fileid);
?> 仔细看这个类写得还有许多需要改进的地方,
1 应该可以写得更oo些。是php4式的代码
2 关于FileBag参数的问题不能相当然,还是让程序控制一下好。
其实就是文件的读写操作,文件的目录存放,以及文件的管理。