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

html-css014

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

<?php require_once("mysql_class.php")

require_once("sys_conf.inc")

header('Content-Type:text/htmlCharset=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/htmlCharset=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/htmlCharset=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

在html中调用php内容,可以用<script src="friendlinks.php"></script>然后在friendlinks.php中调取数据库数据。并输出适当的html,或者输出xml、json都可以,只是图简单的话,只要输出html就行了。