php如何生成utf-8的html文件
php如何生成utf-8的html文件??注意不是简单地加 ,而是生成文件后用记事本打开另存为后编码自动为utf-8 。
------解决方案--------------------
PHP本身是无编码的,所有的字符串通常都视为二进制流。因此只需要输入的字符串为Utf-8即可。若字符串采用其他编码,可以使用iconv系列函数转换编码。
------解决方案--------------------
fwrite ($f,"".iconv('gbk','utf-8',$html));
------解决方案--------------------
------解决方案--------------------
utf-8,在html文件中加入不久好了,然后给你个生成静态html的类
/******************8php静态类*************/
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 = "";
}
// 绑定数据源,参数为一数组
function binddata($arr)
{
$this->datasource = $arr;
}
// 设置文件存放路径
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] == "") { //使用绝对路径
$currentpath = $_server['document_root'];
} else {
$currentpath = $_server['document_root'] . dirname($_server['php_self']);
}
for ($i = 0; $i if ($patharr[$i] == "")
continue;
else
if (is_dir($currentpath . " / " . $patharr[$i]))
$currentpath = $currentpath . " / " . $patharr[$i];
else
mkdir($currentpath = $currentpath . " / " . $patharr[$i]);
}
}
// 生成静态文件
function create()
{
$tmp = $this->templet;
foreach ($this->datasource as $key => $value) {
$tmp = str_replace(" ", $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");










