【问题标题】:PHP fopen and fread proper formatPHP fopen 和 fread 正确格式
【发布时间】:2014-09-13 18:53:00
【问题描述】:

所以我正在尝试获取一个 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)

【问题讨论】:

  • 对不起,我已经编辑了你的帖子两次,第一次编辑我清理了下部的混乱,直到我意识到这是你的实际问题。 ;)

标签: fopen lines fread


【解决方案1】:

以下

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

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

http://php.net/file

【讨论】:

  • 有效!谢谢你的帮助!!
【解决方案2】:

使用 fget

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多