PHP fopen和fread正确的格式

时间:2014-09-13 18:53:01

标签: fopen lines fread

所以我试图获取一个fopen和fread语句来显示日志,并且每个条目都以新行格式化,我如何才能使我的代码采用与.txt相同的格式,

.txt:

[2014/1/19 - 22:49:37] Josh (IP:174.101.171.132) has edited auction 0 expire time to 60
[2014/1/19 - 22:49:43] Josh (IP:174.101.171.132) has edited auction 0 enabled to 1 (Enabled)
[2014/1/19 - 22:49:51] Josh (IP:174.101.171.132) has edited auction 0 item description to Free House
[2014/1/19 - 22:49:59] Josh (IP:174.101.171.132) has edited auction 0 starting bid to 5000000
[2014/1/19 - 22:50:31] Josh (IP:174.101.171.132) has edited auction 0 enabled to 0 (disabled)
[2014/1/19 - 22:50:37] Josh (IP:174.101.171.132) has edited auction 0 item description to none
[2014/1/19 - 22:50:45] Josh (IP:174.101.171.132) has edited auction 0 item description to (none)
[2014/1/19 - 22:50:50] Josh (IP:174.101.171.132) has edited auction 0 starting bid to 0
[2014/1/20 - 11:40:09] Josh (IP:174.101.171.132) has edited auction 0 item description to Testing House
[2014/1/20 - 11:40:14] Josh (IP:174.101.171.132) has edited auction 0 expire time to 1
[2014/1/20 - 11:40:18] Josh (IP:174.101.171.132) has edited auction 0 starting bid to 1
[2014/1/20 - 11:40:21] Josh (IP:174.101.171.132) has edited auction 0 enabled to 1 (Enabled)

PHP返回:

[2014/1/19 - 22:49:37] Josh (IP:174.101.171.132) has edited auction 0 expire time to 60 [2014/1/19 - 22:49:43] Josh (IP:174.101.171.132) has edited auction 0 enabled to 1 (Enabled) [2014/1/19 - 22:49:51] Josh (IP:174.101.171.132) has edited auction 0 item description to Free House [2014/1/19 - 22:49:59] Josh (IP:174.101.171.132) has edited auction 0 starting bid to 5000000 [2014/1/19 - 22:50:31] Josh (IP:174.101.171.132) has edited auction 0 enabled to 0 (disabled) [2014/1/19 - 22:50:37] Josh (IP:174.101.171.132) has edited auction 0 item description to none [2014/1/19 - 22:50:45] Josh (IP:174.101.171.132) has edited auction 0 item description to (none) [2014/1/19 - 22:50:50] Josh (IP:174.101.171.132) has edited auction 0 starting bid to 0 [2014/1/20 - 11:40:09] Josh (IP:174.101.171.132) has edited auction 0 item description to Testing House [2014/1/20 - 11:40:14] Josh (IP:174.101.171.132) has edited auction 0 expire time to 1 [2014/1/20 - 11:40:18] Josh (IP:174.101.171.132) has edited auction 0 starting bid to 1 [2014/1/20 - 11:40:21] Josh (IP:174.101.171.132) has edited auction 0 enabled to 1 (Enabled)

2 个答案:

答案 0 :(得分:0)

使用fgets

fgets从文件中读取一行文本。如果要将其输出到HTML流,则一次输出一行,并在每行后添加<BR>。或者,只需使用<pre></pre>标记并按原样输出整个文件。

答案 1 :(得分:0)

以下

$lines = file('/path/to/file');

为您提供一个数组,其中每个元素都是文件的一行。

http://php.net/file