用PHP读取文本文件并在某个字符串后显示所有文本

Ale*_*lex 2 php string text file

我有一个包含大量文本的文本文件,我想用 PHP 在屏幕上显示其中的一部分。

在某一点有像这样的字符串 ITEM DESCRIPTION:

我想从这个字符串(就在它之后)获取所有内容到文件末尾。

到目前为止,这是我的代码:

$file = "file.txt";
$f = fopen($file, "r");
while ($line = fgets($f, 1000))
  echo $line;
Run Code Online (Sandbox Code Playgroud)

:)

sma*_*sey 5

你如何使用 strstr() 和 file_get_contents() ?

$contents = strstr(file_get_contents('file.txt'), 'ITEM DESCRIPTION:');
# or if you don't want that string itself included:
$s = "ITEM DESCRIPTION:"; # think of newlines as well "\n", "\r\n", .. or just use trim()
$contents = substr(strstr(file_get_contents('file.txt'), $s), strlen($s));
Run Code Online (Sandbox Code Playgroud)