【问题标题】:Can't get ParseDown to parse contents of a file无法让 ParseDown 解析文件的内容
【发布时间】:2020-08-18 18:39:43
【问题描述】:

我对 PHP 还很陌生。我试图让我的代码根据 GET 属性“pgid”的内容读取 Markdown 文件的内容,然后输出它。 这个:

print Parsedown::instance()->text("Testing *Markdown* with **Parsedown**")

输出结果

使用 Parsedown

测试 Markdown

但是这个:

print (Parsedown::instance()->text(readfile("./".$_GET['pgid'].".md")));

?pgid=aboutabout.md 的内容为Testing *Markdown* with **Parsedown**,输出为

使用 **Parsedown** 测试 *Markdown* 39

我不确定为什么我可以让所有部分单独工作,但不能一起工作。

【问题讨论】:

  • 因为readfile 直接写入输出缓冲区,而不是返回它已读取的文件内容。将其替换为file_get_contents
  • @CBroe 我现在已经更改了它并且有效。非常感谢!

标签: php markdown parsedown


【解决方案1】:

PHP 的 readfile()返回文件内容,它输出它们。

你的代码所做的,基本上是这样的:

print readfile($filename); // The print() here is implied by readfile itself.
print (Parsedown::instance()->text(80));

其中 80 是从文件中读取的字节数。

您可能希望使用file_get_contents() 而不是readfile(),它会返回文件的内容。

【讨论】:

  • 我明白了,谢谢!我来自 python 其中 read() 返回文件内容。感谢您的帮助。
猜你喜欢
  • 2017-01-29
  • 2021-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-07
  • 1970-01-01
相关资源
最近更新 更多