PHP静态类
作者:不详 来源:网络 发布时间: 2014-08-21 17:39 点击:
次
[PHP]代码 view source print? 001 ?php 002 /******************8PHP静态类*************/ 003 class Shtml 004 { 005 var $Templet; 006 var $DataSource; 007 var $Dir; 008 009 var $fileName; 010 var $mod; 011 var $handle; 012 013 function Shtml($fileName =
PHP静态类
[PHP]代码
view source
print?
002 |
/******************8PHP静态类*************/ |
013 |
function Shtml($fileName = "") |
015 |
$this->fileName = $fileName; |
017 |
$this->handle = false; |
020 |
$this->DataSource = array(); |
025 |
function BindData($arr) |
027 |
$this->DataSource = $arr; |
031 |
function SetDir($dir) |
035 |
function SetFileName($fileName) |
037 |
return $this->fileName = $fileName; |
044 |
function SetMod($mod) |
046 |
return $this->mod = $mod; |
050 |
if (substr($this->fileName, 0, 1) == "/") |
051 |
$this->fileName = $_SERVER['DOCUMENT_ROOT'] . $this->fileName; |
052 |
if ($this->handle = fopen($this->fileName, $this->mod)) |
053 |
return $this->handle; |
059 |
return fclose($this->handle); |
061 |
function Write($content) |
063 |
return fwrite($this->handle, $content); |
065 |
function MkDir($pathname) |
068 |
str_replace("", "/", $pathname); |
069 |
$pathArr = split("/", $pathname); |
070 |
if ($pathArr[0] == "") { //使用绝对路径 |
071 |
$currentPath = $_SERVER['DOCUMENT_ROOT']; |
073 |
$currentPath = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']); |
075 |
for ($i = 0; $i < count($pathArr); $i++) { |
076 |
if ($pathArr[$i] == "") |
079 |
if (is_dir($currentPath . " / " . $pathArr[$i])) |
080 |
$currentPath = $currentPath . " / " . $pathArr[$i]; |
082 |
mkdir($currentPath = $currentPath . " / " . $pathArr[$i]); |
089 |
$tmp = $this->Templet; |
090 |
foreach ($this->DataSource as $key => $value) { |
091 |
$tmp = str_replace(" < FIELD_" . $key . " > ", $value, $tmp); |
093 |
$this->MkDir(dirname($this->fileName)); |
100 |
function CreateShtml() { |
101 |
ob_start("callback_CteateShtml"); |
104 |
function callback_CteateShtml($buffer) { |
105 |
$page = intval(@$_REQUEST["page"]); |
106 |
$shtml = new Shtml(); |
107 |
$shtml->SetFileName($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . basename($_SERVER['PHP_SELF'], ".php") . ($page == 0 ? "" : "_" . strval($page)) . ".html"); |
108 |
$shtml->Templet = $buffer; |
本文"PHP静态类"由远航站长收集整理而来,仅供大家学习与参考使用。更多
网站制作教程尽在远航站长站。