php獲取文字,php讀取檔案內容的方法

2021-10-25 21:30:30 字數 527 閱讀 4169

php讀取檔案內容的方法

php讀取檔案內容的'方法

第一種讀取方式

**如下:

header("content-type:text/html;charset=utf-8");

//檔案路徑

$file_path="text.txt";

//判斷是否有這個檔案

if(file_exists($file_path))elseelseelseelse{

echo "沒有這個檔案";

//替換字元

$str=str_replace("rn","

",$str);

echo $str;

fclose($fp);

讀取ini配置檔案的函式:

$arr=parse_ini_file("config.ini");

//返回的是陣列

echo $arr['host']."

echo $arr['username']."

echo $arr['password']."

php 讀取文字檔案內容

php讀取檔案內容的三種方法 第一種讀取方式 如下 header content type text html charset utf 8 告訴php預處理器將內容已utf8的格式傳遞給瀏覽器 檔案路徑 file path text.txt 判斷是否有這個檔案 if file exists file...

php 逐行讀取文字檔案

在讀取文字時,我們要注意乙個事情,那就是換行符,應為我們在寫文件時會手動換行,這個換行符需不需要儲存就要看自己的需求了。這裡封裝了兩個方法,乙個保留換行,乙個不保留。path為檔案路徑 檔名 1.不保留換行 1 function read path 11 fclose file 12 user ar...

php 讀取檔案

那如何讀取乙個檔案呢?我們先學乙個函式。int readfile string 檔名 linux類的讀了方式 readfile home paul test.txt windows類的讀取方式 readfile c boot.ini file get contents開啟檔案 上面的是單純打檔案就直...