国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP教程實例:用PHP腳本生成word文檔的程序

2024-05-04 23:02:44
字體:
供稿:網(wǎng)友

php生成word文檔的代碼,這個是用來生產(chǎn)試卷的簡單php代碼

<?php
//初始化session
session_start();
// 包含數(shù)據(jù)庫連接文件和頭文件
?>
<html>
<head>
<title>試卷生成</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<?
include('head.php');
require ('dbconnect.php');
?>
<?php
$juge=0;
for($i=1;($i<100);$i++)
{
$a=$i;
if(isset($_post[$a]))
{
if($juge==0)
$sql.=" id=".$_post[$a];
else
$sql.=" or id=".$_post[$a];
$juge=1;
}
}
if($sql!="")
{
$sql="select * from test where".$sql;
$result_array=array(); //返回數(shù)組
$i=0; //數(shù)組下標
$[email protected]_query($sql,$conn);
while($[email protected]_fetch_object($query_result))
{
$i++;
$cout.=$i."&nbsp;&nbsp;";
$cout.="題目難度:".$row->difficulty."<br>";
$cout.="&nbsp;&nbsp;&nbsp;".$row->content."<br><br>";
}//while

?>
<?php
class word
{
function start()
{
ob_start();
print'<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns=";
}

function save($path)
{

print "</html>";
$data = ob_get_contents();

ob_end_clean();
$this->wirtefile ($path,$data);
}
function wirtefile ($fn,$data)
{
$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}
}
/*-------word class end-------*/
$word=new word;
$word->start();
echo $cout;
$wordname="word/".time().".doc";
$word->save($wordname);//保存word并且結(jié)束.
?>
<div align="center"><a href="<?php echo $wordname ; ?>" target=_blank class="unnamed1">試卷已經(jīng)生成,請點擊這里查看</a>
<?php
}
else
{
?>
</div>
<div align="center"><span class="unnamed1">您輸入的條件不足,請重新輸入!</span>
<?php
}
?>
</div>
</html>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 许昌县| 山阴县| 团风县| 纳雍县| 伊宁县| 石林| 汝州市| 武城县| 汽车| 杂多县| 黄骅市| 天峻县| 安多县| 邵阳市| 肥西县| 楚雄市| 阜阳市| 岗巴县| 宣恩县| 叶城县| 九台市| 田林县| 塔城市| 万荣县| 禹州市| 巍山| 巴塘县| 蒲江县| 商城县| 类乌齐县| 汕尾市| 资溪县| 黑河市| 伊宁市| 启东市| 射洪县| 麻阳| 轮台县| 保山市| 岑巩县| 高唐县|