php生成word文档,并可以下载
<?php
if($_POST['str'])
{
header('Content-type: application/doc');
header('Content-Disposition: attachment; filename="downloaded.doc"');
echo iconv("UTF-8","GB2312",$_POST['str']);
}
?>
<a href="javascript:void(0)" onclick="downword()">下载</a>
<div id="word" style="display:none">加息预期下银行再推固息房贷
</div>
<form action="" method="POST" name="form">
<textarea style="display:none" name="str" id="down"/></textarea>
</form>
<script>
function downword()
{
var doc=document.getElementById("word").innerHTML;
document.getElementById("down").value=doc;
document.form.submit();
}
</script>
如果想生成其它的文件,将doc改成其它的扩展名就OK了
相关文档:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type = "text/css">
&nbs ......
每次我们访问 PHP 脚本的时候,都是当所有的PHP脚本执行完成后,我们才得到返回结果。如果我们需要一个脚本持续的运行,那么我们就要通过 PHP 长连接的方式,来达到运行目的。
每个 PHP 脚本都限制了执行时间,所以我们需要通过 set_time_limit 来设置一个脚本的执行时间为无限长;然后使用 flush() 和 ob_flush() ......
<?php
header("Content-Type:image/png");
srand((double)microtime()*1000000);
$img_height=20;
$img_width=60;
$im=@imagecreate($img_width,$img_height) or die("不能初始化GD文件流");
$background_color=imagecolorallocate($im,255,255,255);
$text_color=imagecolorallocate($im,233,14,91);
......
<?php
define('SMARTY_TMP_DIR','C:/php5/Smarty-2.6.13/');
define('SMARTY_DIR','C:/php5/Smarty-2.6.13/libs/'); //SMARTY_DIR ->smarty keyword,must be defined as libs dectory
require_once(SMARTY_DIR.'Smarty.class.php');
//建立一个smarty对象
$smarty = new Smarty;
$smarty->template_dir = ......
//计算距公元1年1月1日的天数,$yyyy年分,$mm月份,$dd日
function datelocal($yyyy,$mm,$dd){
$monthdays = array(31,28,31,30,31,30,31,31,30,31,30,31); //非闰年的月份天数
//判断是否为闰年,闰年$leapyear = 1,否则 $leapyear = 0
if($yy%4==0 && $yyyy%100!=0 || $yyyy%400==0)
$leapyear = 1;
els ......