0

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

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

结果输出

使用Parsedown测试Markdown

但是这个:

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

和存在?pgid=about的内容,输出是about.mdTesting *Markdown* with **Parsedown**

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

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

4

1 回答 1

1

PHPreadfile()返回文件内容,而是输出它们。

您的代码的作用基本上是这样的:

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

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

而不是readfile(),您可能想要使用file_get_contents(),它确实返回文件的内容。

于 2020-05-04T10:58:04.160 回答