您现在的位置是:首页 >

静态类实例化 PHP静态类

火烧 2021-11-01 06:21:09 1071
PHP静态类 view ource ri t? lt ? h /****************** PHP静态类*************/cla S { var$Tem let var$DataS
静态类实例化 PHP静态类

PHP静态类  

view source   print? <?php /****************** PHP静态类*************/classS {    var$Templet;    var$DataSource;    var$Dir;     var$fileName;    var$mod;    var$handle;     functionS($fileName= "")    {    $this >fileName = $fileName;    $this >mod = "wb";    $this >handle = false;     $this >Templet = "";    $this >DataSource = array();    $this >Dir = "";    }     // 绑定数据源 参数为一数组    functionBindData($arr)    {    $this >DataSource = $arr;    }     // 设置文件存放路径    functionSetDir($dir)    {    $this >Dir = $dir;    }    functionSetFileName($fileName)    {    return$this >fileName = $fileName;    }     functionGetMod()    {    return$this >mod;    }    functionSetMod($mod)    {    return$this >mod = $mod;    }    functionOpen()    {    if(substr($this >fileName ) == "/")    $this >fileName = $_SERVER[ DOCUMENT_ROOT ] $this >fileName;    if($this >handle = fopen($this >fileName $this >mod))    return$this >handle;    else   returnfalse;    }    functionClose()    {    returnfclose($this >handle);    }    functionWrite($content)    {    returnfwrite($this >handle $content);    }    functionMkDir($pathname)    {    $currentPath= "";    str_replace("""/"$pathname);    $pathArr= split("/"$pathname);    if($pathArr[ ] == "") { //使用绝对路径    $currentPath= $_SERVER[ DOCUMENT_ROOT ];    } else{    $currentPath= $_SERVER[ DOCUMENT_ROOT ] dirname($_SERVER[ PHP_SELF ]);    }    for($i= ; $i< count($pathArr); $i++) {    if($pathArr[$i] == "")    continue;    else   if(is_dir($currentPath" / "$pathArr[$i]))    $currentPath= $currentPath" / "$pathArr[$i];    else   mkdir($currentPath= $currentPath" / "$pathArr[$i]);    }    }     // 生成静态文件    functionCreate()    {    $tmp= $this >Templet;    foreach($this >DataSource as$key=> $value) {    $tmp= str_replace(" < FIELD_"$key" > "$value$tmp);    }    $this >MkDir(dirname($this >fileName));    $this >Open();    $this >Write($tmp);    $this >Close();    } }  functionCreateS() {    ob_start("callback_CteateS"); }  functioncallback_CteateS($buffer) {    $page= intval(@$_REQUEST["page"]);    $s= newS();    $s >SetFileName($_SERVER[ DOCUMENT_ROOT ] dirname($_SERVER[ PHP_SELF ]) "/"basename($_SERVER[ PHP_SELF ] " php") ($page== ? "": "_"strval($page)) " ");    $s >Templet = $buffer;    $s >Create();    return$buffer; } ?> lishixinzhi/Article/program/PHP/201311/21105  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码