php从数据库里读出的HTML代码然后执行怎么实现

如题所述

<?php require_once("mysql_class.php");
require_once("sys_conf.inc");
header('Content-Type:text/html;Charset=GBK;');
$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
mysql_select_db($DBNAME); //选择数据库my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];
$content=$row[name];
if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个
{
mkdir("up");
}$up="up/";
echo $path=$up.$row[id_lang].'.htm';
$fp=fopen("tmp.htm","r"); //只读打开模板
$str=fread($fp,filesize("tmp.htm"));//读取模板中内容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替换内容
fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径
fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //删除文件
?><?php require_once("mysql_class.php");
require_once("sys_conf.inc");
header('Content-Type:text/html;Charset=GBK;');
$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
mysql_select_db($DBNAME); //选择数据库my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];
$content=$row[name];
if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个
{
mkdir("up");
}$up="up/";
echo $path=$up.$row[id_lang].'.htm';
$fp=fopen("tmp.htm","r"); //只读打开模板
$str=fread($fp,filesize("tmp.htm"));//读取模板中内容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替换内容
fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径
fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //删除文件
?><?php require_once("mysql_class.php");
require_once("sys_conf.inc");
header('Content-Type:text/html;Charset=GBK;');
$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
mysql_select_db($DBNAME); //选择数据库my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];
$content=$row[name];
if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个
{
mkdir("up");
}$up="up/";
echo $path=$up.$row[id_lang].'.htm';
$fp=fopen("tmp.htm","r"); //只读打开模板
$str=fread($fp,filesize("tmp.htm"));//读取模板中内容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替换内容
fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径
fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //删除文件
?> 用以上先生成一个HTML文件,然后再用require_once("aaa.html");引进来就OK
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网