導航:首頁 > 編程語言 > phpfwrite追加

phpfwrite追加

發布時間:2023-03-16 19:06:49

php 打開一個名為hello.txt的文件,並向其文件內追加寫入"Hello World!"字元串

<?php
$myFile=fopen("hello.txt","a") or die("unable to open file!");
$txt="Hello World!";
fwrite($myFile,$txt);
fclose($myFile);
?>

Ⅱ php怎麼把數據寫入文本文件

php數據寫入文本文件的具體操作步驟如下:

1、使用touch命令建立一個a.php的文件。

Ⅲ PHP文件寫入的幾種方法

通過fwrite
$file = fopen("test.txt","a+"); //次方法會自動生成文件test,txt,a表示追加寫入,
//w代表替換寫入 fwrite($file,"寫入代碼"); fclose($file);
file_put_content()方法寫入

file_put_contents("test.txt","奧斯卡老\r\n頓積分");//這里說一下\r\n在雙引號下
//才會換行如果單引號就識別不了
//如果想追加寫入內容,這個函數還有第三個參數FILE_APPEND

Ⅳ PHP將數據寫入txt文件

//記錄返回值

        $write_data_a = [

            'html_url'  =>  $getUrl,

            'ip'    => $this->get_real_ip(),

            'time'  =>  date("Y-m-d H:i:s",time()),

            'res'   => $response

        ];

//轉化為JSON

        $write_data_a = json_encode($write_data_a) . '||' . "\n";

        $date = date("Y-m-d", time());

//項目路徑目錄,判斷是否存在,不存在則創建

        $lujing = "./360_mobile_res_sd";

        if(!is_dir($lujing)){

            mkdir(iconv("UTF-8", "GBK", $lujing),0777,true);

        }

//文件,判斷是否存在,不存在則創建

        $TxtFileName = "./360_mobile_res_sd/" . $date . "_2.txt";

        //以讀寫方式打寫指定文件,如果文件不存則創建

        if(file_exists($TxtFileName))

        {

//存在,追加寫入內容

            file_put_contents($TxtFileName, $write_data_a, FILE_APPEND);

        }

        else

        {

//不存在,創建並寫入

            if( ($TxtRes=fopen ($TxtFileName,"w+")) === FALSE){

                exit();

            }

            if(!fwrite ($TxtRes,$write_data_a)){ //將信息寫入文件

                fclose($TxtRes);

                exit();

            }

            fclose ($TxtRes); //關閉指針

        }

閱讀全文

與phpfwrite追加相關的資料

熱點內容
為什麼要編譯源代碼 瀏覽:819
輸入法freetype交叉編譯 瀏覽:436
電阻單片機代號 瀏覽:469
來畫app怎麼添加對話框 瀏覽:318
python序列化分布式 瀏覽:107
域名伺服器是什麼形式 瀏覽:681
rsa加密解密速度快 瀏覽:924
mac電腦如何單片機開發 瀏覽:547
紀念日app怎麼用小插件 瀏覽:331
如何更改安卓手機所在地區 瀏覽:217
程序員負債120萬 瀏覽:80
階層pdf 瀏覽:380
linuxgit安裝配置 瀏覽:319
用源碼搭建app要改什麼 瀏覽:42
密碼學教程pdf 瀏覽:3
亞馬遜做的加密貨幣 瀏覽:81
怎麼搭建雲播伺服器 瀏覽:867
網站客服機器人源碼 瀏覽:317
2021程序員的出路 瀏覽:547
發行與承銷pdf 瀏覽:945