php生成Excel文件 實現(xiàn)代碼_PHP教程
推薦:PHP-redis命令文檔Redis本質(zhì)上一個Key/Value數(shù)據(jù)庫,與Memcached類似的NoSQL型數(shù)據(jù)庫,但是他的數(shù)據(jù)可以持久化的保存在磁盤上,解決了服務(wù)重啟后數(shù)據(jù)不丟失的問題,它的值可以是string(字符串)、list(列表)、sets(集合)或者是ordered sets(被排序的集合),所有的數(shù)據(jù)類型都具有push/pop
<p>有段日子沒有更新博客了,生怕被百度遺忘啊,biu~biu~.最近有個項目需要統(tǒng)計網(wǎng)站的url和title,保存在excel里面,下面是具體的代碼</p>
<pre class="php" name="code"><!--p
//php生成excel報表,是通過發(fā)送header()頭信息完成的
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
//告知瀏覽器文件名稱,并要求客戶端下載
header("Content-Disposition:filename=test.xls");
header("Pragma: no-cache");
header("Expires: 0");
$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
mysql_select_db('novartis') or die('Could not select database');
mysql_query("SET NAMES gb2312");
$query = 'SELECT title,keywords,url,description FROM cms_content';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// 用 HTML 顯示結(jié)果
//$str =mb_convert_encoding ("測試1","gb2312","utf-8");
echo "Title\t";
echo "Keywords\t";
echo "Description\t";
echo "URL\t\n";
/* 格式: 換行:"\t\n": 單元格之間: "\t" */
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo $line['title']."\t";
echo $line['keywords']."\t";
echo $line['description']."\t";
echo $line['url']."\t\n";
}
// 釋放結(jié)果集
mysql_free_result($result);
// 關(guān)閉連接
mysql_close($link);
-->
</pre>
<div> </div>
分享:PHP變量引用(&)、函數(shù)引用和對象引用1.變量的引用 PHP 的引用 兩個變量的指針指向同一內(nèi)存地址 $a=ABC;$b =$a;echo $a;//這里輸出:ABCecho $b;//這里輸出:ABC$b=EFG;echo $a;//這里$a的值變?yōu)镋FG 所以輸出EFGecho $b;//這里輸出EFG 2.函數(shù)的引用傳遞(傳址調(diào)用) function test($a){$a=$a+100;}$b=1;echo
- 相關(guān)鏈接:
- 教程說明:
PHP教程-php生成Excel文件 實現(xiàn)代碼
。