PHP how to generate utf-8 HTML file

Source: Internet
Author: User
How PHP generates utf-8 HTML files
How does PHP generate utf-8 HTML files?? Note that it is not simple to add Instead, the file is generated after you open the Save as after using Notepad as the encoding is automatically utf-8.

------Solution--------------------
PHP itself is non-encoded, and all strings are usually treated as binary streams. So only the string you need to enter is Utf-8. If the string has other encodings, you can use the Iconv series function to convert the encoding.
------Solution--------------------
Fwrite ($f, "\XEF\XBB\XBF". Iconv (' GBK ', ' utf-8 ', $html));

------Solution--------------------
discuss

Fwrite ($f, "\XEF\XBB\XBF". Iconv (' GBK ', ' utf-8 ', $html));

------Solution--------------------
Utf-8, add in HTML file Soon enough, and then give you a class that generates static HTML
/******************8php Static Class *************/
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 = "";
}

Bind data Source, parameter is an array
function Binddata ($arr)
{
$this->datasource = $arr;
}

Set File storage path
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] = = "") {//Use absolute path
$currentPath = $_server[' document_root ');
} else {
$currentPath = $_server[' Document_root '). DirName ($_server[' php_self ');
}
for ($i = 0; $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]);
}
}

Generating static files
function Create ()
{
$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 ();
}
}

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");
  • Related Article

    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.