Easy to use PHP to generate static page class (non smarty) 1th/2 page _php tips

Source: Internet
Author: User
Tags save file static class
Copy Code code as follows:

/*********************/
/* */
* version:5.2.5 * *
* author:liqiangwork#sohu.com * *
* qq:570937581 * *
/* */
/*********************/
-----------------------------generate a static class-------------------------------
Class makehtml{
Public $MbUrl, $OUTURL, $AllHtml, $SouChar, $ObjChar; Variable
Public $row; Cursor
Public $Shuzusou, $Shuzuobj; Array of substituted strings
-----------------------initialization-------------------------
function __construct () {//initialization
$this->mburl= "";
$this->outurl= "";
$this->allhtml= "";
$this->sql= "";
$this->souchar= "";
$this->objchar= "";
}
-----------------------------automatically replace by field---------------------------
function Autoreplace () {
------------------automatically gets the string to replace-------------------
$tlen =count ($row);
$shuzu 1=array ();
$shuzu 2=array ();
if ($row) {
$i = 0;
foreach ($row as $key => $value) {
$shuzu 2[i]= "<=\$". $key. " \$> ";
$shuzu 1[i]= $value;
$i + +;
}
$this->replacehtml (SHUZU2,SHUZU1);
}
------------------automatically gets the string to replace-------------------
}
-----------------------------automatically replaced by field------------------------
-----------------------------Bulk Substitution Array--------------------------
function replacehtml ($Shuzusou, $Shuzuobj) {//Bulk substitution array
if (count ($Shuzusou)!=count ($Shuzuobj)) {
Exit ("Replace array mismatch");
}
if ($this->allhtml== "") {
Exit ("No content to replace");
}
for ($i =0; $i <count ($Shuzusou); $i + +) {
$this->allhtml=str_replace ($Shuzusou [$i], $Shuzuobj [$i], $this->allhtml);
Print ("<br>". $Shuzusou (i). " = ". $Shuzuobj (i)." <br> ")
}
}
-----------------------------The batch substitution array is completed--------------------------
-----------------------------Read the file---------------------------------
function Readfile () {
$file =fopen ($this->mburl, "R");
$fsize =filesize ($this->mburl);
$this->allhtml=fread ($file, $fsize);
Fclose ($file);
}
-----------------------------Read the file is complete------------------------------
-----------------------------Save the file---------------------------------
function SaveFile () {
$file =fopen ($this->outurl, "w");
Fwrite ($file, $this->allhtml);
Fclose ($file);
}
-----------------------------Save file is complete------------------------------
}
------------------------------generate a static class complete-------------------------------

Related examples:
Current 1/2 page 12 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.