doujie7497
2016-10-18 18:04
浏览 383

在HTML div中显示文件夹中的所有文本文档?

I have a folder of reviews in the form of .txt documents.

I want to be able to load these into a "review showcase" panel on the site. So it would show off what reviews we already have.

I've figured out with PHP how to get the form to save the information in the fields as a .txt file, but now I'm wondering how do I put all the .txt files into the div?

I have the div configured to scroll, so if I have lets say five reviews, the person browsing can scroll through to read all five of them.

Everything I've seen so far only seems to say "how to put ONE file in the div" like helloworld.txt but all of my .txt documents have different names.

图片转代码服务由CSDN问答提供 功能建议

我有 .txt 文件形式的评论文件夹。

我希望能够将这些加载到网站上的“评论展示”面板中。 所以它会展示我们已经拥有的评论。

我已经找到了PHP如何获取表单将信息保存在字段中作为 .txt 文件,但现在我想知道如何将所有 .txt 文件放入div中?

我已经将div配置为滚动,所以如果我可以说五个评论,浏览者可以滚动浏览所有五个评论。 < 到目前为止我所看到的所有内容似乎只是说“如何将一个文件放在div中”,如 helloworld.txt ,但我的所有。 txt 文档都有所不同 名字。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsoihsnz85757 2016-10-18 18:14
    已采纳

    If you want to load all of the *.txt files in a directory you may be interested in glob() something like this would work.

    $contents = '';
    foreach(glob('/path/to/files/*.txt') as $txtFile) {
        $contents .= file_get_contents( $txtFile );
    }
    echo $contents;
    

    The way this works is that the glob() function looks for txt files in the directory specified. This returns an array of filenames.

    The foreach() construct then iterates through that array. On each iteration the $txtFile variable gets set to be equal to the next value in the file list.

    file_get_contents() then reads the txt file into a string which is appended to $content note the .= operator.

    Note, that doesn't do any formatting, you may want to wrap each review in its own block element or something like that.

    打赏 评论

相关推荐 更多相似问题