12 php操作檔案

2021-10-07 18:41:59 字數 830 閱讀 8364

<

!doctype html>

"utf-8"

>

"viewport"

content=

"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"

>

"x-ua-compatible" content=

"ie=edge"

>

document<

/title>

<

/head>

<?php

php檔案操作

寫入乙個檔案

//1.建立乙個字串

//$str ='i am first php write file';

2.開啟乙個檔案流

//$f= @fopen('firsttxt.txt','w');

3.判斷檔案流開啟是否成功

//if ($f)

//else

//讀取file 輸出到螢幕

1.開啟檔案流

//$f=@fopen('firsttxt.txt','r');

//if ($f)

////}

//else

//

////一次性讀取所有行

echo

file_get_contents

('firsttxt.txt'

)?>

<

/body>

<

/html>

php操作檔案

實現php寫入,讀取,替換檔案內容。先解釋一下,主要用到 fopen 檔名.副檔名 操作方式 fwrite 讀取的檔案,寫入的檔案 fclose 開啟的物件變數 寫入檔案 w表示以寫入的方式開啟檔案,如果檔案不存在,系統會自動建立 file pointer fopen sb.log a fwrite...

PHP檔案處理 操作檔案

除了能夠對檔案內容進行讀寫,對檔案本身相同也能夠進行操作,如拷貝檔案 又一次命名 檢視改動日期等。php內建了大量的檔案操作函式,經常使用的檔案函式例如以下表 函式原型 函式說明 舉例bool copy string path1,string path2 將檔案從path1拷貝到path2。假設成功...

php操作資料夾

對檔案內容操作 readfile a.txt 讀取文字內容 var dump file a.txt 索引陣列對每一行排序 str file get contents a.txt 把檔案內容原樣輸出相當於python的 var dump str file put contents tst.txt 這是...