php提交過來的數(shù)據(jù)生成為txt文件
一共兩個文件,具體鏈接數(shù)據(jù)庫的部分給直接去除了,前臺是提交的文字部分,一行一個,在提交后另一個程序文件進(jìn)行處理,然后按照提交的文件名生成相應(yīng)的txt 文件,并在txt 文件中加入數(shù)據(jù),在使用之前需要先在根目錄下新建 test 文件下。
前臺表單文件如下(保存為dcwz.php):
<?php
error_reporting(0);
//require_once("../config.php");
//require_once("../admin/ly_check.php");
//$sql="select * from leibie";
//$rs=mysql_query($sql);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標(biāo)題文檔</title>
<link type="text/css" rel="stylesheet" href="/xwyfb/fb_css.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<div class="dcwj">
<form id="tjsd" name="tjsd" action="dcwj_cl.php" method="post" onSubmit="return checkForm()" >
<div class="dcwj_div1"><p class="dcwj_div1_p1">現(xiàn)在項目類別:</p><p class="dcwj_div1_p2"><select name="liebie" id="liebie">
<?php
while($rows=mysql_fetch_assoc($rs)){
?>
<option selected="selected" value="<?php echo $rows["lid"];?>"><?php echo $rows["lid"]."=>".$rows["yyname"]."=>".$rows["leibie"];?></option>
<?php
}
?>
</select></p></div>
<div class="dcwj_div1"><p class="dcwj_div1_p1">模糊關(guān)鍵詞:</p><p class="dcwj_div1_p2"><input name="mhgjc" id="mhgjc" value="" type="text"></p></div>
<div class="dcwj_div2">
<p class="dcwj_div2_p1">請輸入標(biāo)題<br>*(一行一個)</p>
<p class="dcwj_div2_p2"><textarea name="biaoti" id="biaoti" class="dcwj_biaoti" cols="50" rows="100"></textarea></p></div>
<div class="dcwj_div2"><input name="submit" type="submit" value="提交"></div>
</form>
</div>
</body>
</html>
生成 txt 文件的處理程序如下所示(保存為dcwj_cl.php):
<?php
$biaoti_cl=explode("\n",$biaoti);
$biaoti_num=count($biaoti_cl);
$file_type = "txt";
for($i=0;$i<$biaoti_num;$i++){
$file_name = mb_convert_encoding($biaoti_cl[$i],'GBK',"UTF-8");
$data[] = array("tom","boy",20);
$dir=dirname(__FILE__)."\\text\\";
$string = "";
foreach($data as $k =>$v){
foreach($v as $vstr){
$string .= mb_convert_encoding($vstr,'GBK',"UTF-8");
}
}
$string .="\r\n";
$filedir = $dir.trim($file_name).".".$file_type;
$fileurl = str_replace('',' ',$filedir);
$fp = fopen($fileurl,"a+");
echo '創(chuàng)建'.$fileurl.'<br>';
fwrite($fp,$string);
fclose($fp);
}
?>
以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)php程序設(shè)計有所幫助。
相關(guān)文章
PHP實(shí)現(xiàn)圖片的等比縮放和Logo水印功能示例
這篇文章主要介紹了PHP實(shí)現(xiàn)圖片的等比縮放和Logo水印功能,結(jié)合實(shí)例形式分析了php圖片等比例縮放及l(fā)ogo水印添加操作技巧,需要的朋友可以參考下2017-05-05
ThinkPHP5.0之底層運(yùn)行原理執(zhí)行流程分析
run()方法可以在/thinkphp/library/think/App.php文件中找到對應(yīng)方法,這個方法是整個框架的核心方法,實(shí)現(xiàn)了路由轉(zhuǎn)換、獲取調(diào)度信息、根據(jù)調(diào)度信息執(zhí)行相應(yīng)模塊控制器的方法、獲取方法返回數(shù)據(jù)、將返回數(shù)據(jù)賦值給Response對象等一系列操作。2023-05-05
php實(shí)現(xiàn)背景圖上添加圓形logo圖標(biāo)的方法
這篇文章主要介紹了php實(shí)現(xiàn)背景圖上添加圓形logo圖標(biāo)的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了php背景圖添加logo圖標(biāo)的操作步驟與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-11-11
PHP Header用于頁面跳轉(zhuǎn)時的幾個注意事項
大家都知道header函數(shù)中Location類型的標(biāo)頭是一種特殊的header調(diào)用,常用來實(shí)現(xiàn)頁面跳轉(zhuǎn),在新手剛學(xué)習(xí)的時候有些注意事項要注意,下面通過本文來詳細(xì)看看吧。2016-10-10
php實(shí)現(xiàn)壓縮合并js的方法【附demo源碼下載】
這篇文章主要介紹了php實(shí)現(xiàn)壓縮合并js的方法,涉及php壓縮文件類JSMin的相關(guān)調(diào)用與使用技巧,并附帶了完整的demo源碼供讀者下載參考,需要的朋友可以參考下2016-09-09
php mb_substr()函數(shù)截取中文字符串應(yīng)用示例
substr()函數(shù)用來截取字符串,但是對于中文字符會出現(xiàn)問題,而mb_substr()和mb_strcut這兩個函數(shù)可以,下面為大家介紹其具體用法2014-07-07

