新聞中心
PHP怎么寫入TXT文檔??
php 寫入txt:
在成都等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作定制網(wǎng)站建設(shè),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),全網(wǎng)整合營銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,成都網(wǎng)站建設(shè)費用合理。
PHP
function writelog($str)
{
$open=fopen("log.txt","a" );
fwrite($open,$str);
fclose($open);
}
'a' 寫入方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創(chuàng)建之。
'a+' 讀寫方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創(chuàng)建之。
php txt 換行
"\r\n"
不可用單引號.
PHP將數(shù)據(jù)寫入txt文件
//記錄返回值
? ? $write_data_a = [
? ? ? ? 'html_url'? =? $getUrl,
? ? ? ? 'ip'? ? = $this-get_real_ip(),
? ? ? ? 'time'? =? date("Y-m-d H:i:s",time()),
? ? ? ? 'res'?? = $response
? ? ];
//轉(zhuǎn)化為JSON
? ? $write_data_a = json_encode($write_data_a) . '||' . "\n";
? ? $date = date("Y-m-d", time());
//項目路徑目錄,判斷是否存在,不存在則創(chuàng)建
? ? $lujing = "./360_mobile_res_sd";
? ? if(!is_dir($lujing)){
? ? ? ? mkdir(iconv("UTF-8", "GBK", $lujing),0777,true);
? ? }
//文件,判斷是否存在,不存在則創(chuàng)建
? ? $TxtFileName = "./360_mobile_res_sd/" . $date . "_2.txt";
? ? //以讀寫方式打?qū)懼付ㄎ募?,如果文件不存則創(chuàng)建
? ? if(file_exists($TxtFileName))
? ? {
//存在,追加寫入內(nèi)容
? ? ? ? file_put_contents($TxtFileName, $write_data_a, FILE_APPEND);
? ? }
? ? else
? ? {
//不存在,創(chuàng)建并寫入
? ? ? ? if( ($TxtRes=fopen ($TxtFileName,"w+")) === FALSE){
? ? ? ? ? ? exit();
? ? ? ? }
? ? ? ? if(!fwrite ($TxtRes,$write_data_a)){ //將信息寫入文件
? ? ? ? ? ? fclose($TxtRes);
? ? ? ? ? ? exit();
? ? ? ? }
? ? ? ? fclose ($TxtRes); //關(guān)閉指針
? ? }
php讀取數(shù)據(jù)庫數(shù)據(jù) 寫進 txt
注意。當(dāng)你生成txt文件時,先將txt另存為一下修改一下txt文件的編碼,txt默認(rèn)是采用ascii格式,換成utf8吧
新聞名稱:包含php寫數(shù)據(jù)進txt的詞條
瀏覽路徑:http://www.dlmjj.cn/article/doscpco.html