PHP讀取日誌裡資料方法理解

2021-09-07 03:44:46 字數 464 閱讀 3345

需要函式:

fopen($file, "r")開啟檔案

fgets($file, 1024 * 10)讀取一行,注意設定位元組數大小,預設的1024b可能太小了

strpos($log, '---') 找到某一標記首次出現的位置

trim()去除空格

substr($pre, 0, $index_q)擷取某一標記之間的字元

explode()通過某標記轉為陣列

end($logs)將 array的內部指標移動到最後乙個單元並返回其值

<?php

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

$file = 'test.txt';

$fp = @fopen($file,'r');

if($fp)

}

PHP讀取日誌裡資料方法理解

需要函式 fopen file,r 開啟檔案 fgets file,1024 10 讀取一行,注意設定位元組數大小,預設的1024b可能太小了 strpos log,找到某一標記首次出現的位置 trim 去除空格 substr pre,0,index q 擷取某一標記之間的字元 explode 通過...

PHP讀取日誌裡資料方法理解

需要函式 fopen file,r 開啟檔案 fgets file,1024 10 讀取一行,注意設定位元組數大小,預設的1024b可能太小了 strpos log,找到某一標記首次出現的位置 trim 去除空格 substr pre,0,index q 擷取某一標記之間的字元 explode 通過...

PHP魔術方法理解

function exists dump else output output echo output class magic 給乙個未定義的屬性賦值時呼叫 param string name 呼叫的未定義的屬性名稱 param mixed value 對未定義的屬性賦值的值 public func...