$keynames=array(
成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于做網(wǎng)站、成都網(wǎng)站建設(shè)、沿灘網(wǎng)絡(luò)推廣、重慶小程序開發(fā)、沿灘網(wǎng)絡(luò)營(yíng)銷、沿灘企業(yè)策劃、沿灘品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供沿灘建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:jinyejixie.com
'0'='訂單號(hào)',
'1'='項(xiàng)目名稱',
'2'='單價(jià)',
'3'='數(shù)量',
'4'='運(yùn)費(fèi)',
'5'='金額',
'6'='支付狀態(tài)',
'7'='支付時(shí)間',
'8'='選項(xiàng)',
'9'='備注',
'10'='收件人',
'11'='手機(jī)',
'12'='送貨地址',
'13'='物流',
'14'='物流單號(hào)'
);
down_excel($eorders, $keynames,$array_key, $name);
//生成簡(jiǎn)單excel。table生成。生成excel非標(biāo)準(zhǔn)。phpexcel生成的標(biāo)準(zhǔn),可讀寫excel
function down_xls($data, $keynames, $name = 'dataxls') {
$xls [] = "htmlmeta http-equiv=content-type content=\"text/html; charset=UTF-8\"bodytable border='1'";
$xls [] = "trtdID/tdtd" . implode ( "/tdtd", array_values ( $keynames ) ) . '/td/tr';
foreach ( $data as $o ) {
$line = array (++ $index );
foreach ( $keynames as $k = $v ) {
$line [] = $o [$k];
}
$xls [] = 'trtd' . implode ( "/tdtd", $line ) . '/td/tr';
}
$xls [] = '/table/body/html';
$xls = join ( "\r\n", $xls );
header ( 'Content-Disposition: attachment; filename="' . $name . '.xls"' );
die ( mb_convert_encoding ( $xls, 'UTF-8', 'UTF-8' ) );
}
//add by wqc excel
function down_excel($data, $keynames,$array_key, $name = 'dataxls') {
require_once(dirname(dirname(dirname(__FILE__))) . '/PHPExcel/PHPExcel.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/PHPExcel/PHPExcel/IOFactory.php');
//實(shí)例化phpexcel
$objPHPExcel = new PHPExcel();
$objPHPExcel-getActiveSheet()-getDefaultColumnDimension()-setWidth(16);//設(shè)置單元格寬度
$objPHPExcel-getActiveSheet()-setTitle('kutuan');//設(shè)置當(dāng)前工作表的名稱
foreach($keynames as $k=$r){
$objPHPExcel-getActiveSheet()-getStyleByColumnAndRow($k, 1)-getFont()-setBold(true);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow($k, 1, $r);
}
foreach($data as $key=$value)
{
//$objPHPExcel-getSheet(1)-getProtection()-setSheet(true);
//$objPHPExcel-getSheet(1)-protectCells(0, ($key+2),$value['id']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(0, ($key+2),$value['id']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(1, ($key+2),$value['team_id']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(2, ($key+2),$value['price']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(3, ($key+2),$value['quantity']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(4,($key+2),$value['fare']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(5, ($key+2),$value['origin']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(6, ($key+2),$value['state']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(7, ($key+2),$value['pay_time']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(8, ($key+2),$value['condbuy']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(9, ($key+2),$value['remark']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(10, ($key+2),$value['realname']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(11, ($key+2),$value['mobile']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(12, ($key+2),$value['address']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(13, ($key+2),$value['express']);
$objPHPExcel-getActiveSheet()-setCellValueByColumnAndRow(14, ($key+2),$value['express_no']);
}
$objPHPExcel-setActiveSheetIndex(0);//設(shè)置打開excel時(shí)顯示哪個(gè)工作表$name.
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".$name);
header("Content-Transfer-Encoding: binary");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
return $objWriter-save('php://output');
}
使用form表單post數(shù)據(jù)到PHP,然后用file_put_contents($fileName, $data)寫入文件,$fileName是文件名,$data是要寫入的數(shù)據(jù)
新建一個(gè)a.php文件,將下面的復(fù)制進(jìn)去訪問一下,填寫后點(diǎn)擊提交,會(huì)生成一個(gè)a.txt的文件,里面是你填寫的內(nèi)容
可能會(huì)有一個(gè)notice的報(bào)錯(cuò),不必理會(huì)
?php
$data = $_POST['text'];
$fileName = 'a.txt';
file_put_contents($fileName, $data);
?
!doctype html
html
head
meta charset="utf-8"
titletest/title
/head
body
form action="./a.php" method="post"
textarea name="text" id="" cols="30" rows="10"/textarea
input type="submit" value="提交"
/form
/body
/html
//第一種?
?php
$conn?=?mysql_connect("主機(jī)名","用戶名","密碼");
mysql_select_db("數(shù)據(jù)庫(kù)名",$conn);
$sql?=?"select?*?from?user";
$result?=?mysql_query($sql);
$data="";
while($row?=?mysql_fetch_row($result)){
foreach($row?as?$v){
$data?.=$v."|";??????//加個(gè)樹線隔開字段
}
nl2br($data);????//讀完一行回車
}
file_put_contents("abc.txt",$data);
//第二種
?php
$filename?=?"abc.txt";
$res?=?fopen($filename,"r");
while(!feof($res)){
$buffer?=?fgets($res);
$buffer?=?str_replace('?',?'|',?$buffer);?
$array?=?explode('|',?$buffer);?
foreach($array?as?$v){
if(strlen($v)0){
$arr[]?=?$v;
}
}
}
fclose($res);
//組裝數(shù)組插入數(shù)據(jù)庫(kù)就可以了
把你要保存的數(shù)據(jù)序列化一下,保存到文本中,如果需要修改,則從文本中取出,在反序列化化,在修改后,在序列化一下,保存到文本中。
文本的讀寫 參考fopen 等函數(shù)
?PHP
$file_name="1.txt";
$fp=fopen($file_name,'r');
$str=array();
$bian=0;
while(!feof($fp))
{
$buffer=fgets($fp);
$str[$bian]=$buffer;
$bian++;
}
fclose($fp);
var_dump($str);
$k=fopen("2.txt","a+");
for($z=0;$z2;$z++){
fwrite($k,$str[$z]);
}
fclose($k);
?
網(wǎng)頁標(biāo)題:php獲取保存數(shù)據(jù)到文件 php獲取保存數(shù)據(jù)到文件里
URL標(biāo)題:http://jinyejixie.com/article12/hepcgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、微信公眾號(hào)、營(yíng)銷型網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷推廣、網(wǎng)站排名、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)