我正在尝试 Michel Fortin 的 PHP-Markdown 库,但在让它在我的服务器上运行时遇到一些问题。
我已将解析器库文件上传到我的服务器的 / 子文件夹中。我的 testmd.php 文件位于上一层文件夹中。目前,我正在使用下面的代码来 require_once 文件,但是我的 markdown 测试行(链接)没有被解析。我还需要执行其他操作或包含其他内容才能使 PHP-markdown 库适用于这样的示例吗?
testmd.php
<?php
require_once ('subfolder/Markdown.inc.php');
require_once ('subfolder/includetest.php');
?>
<html>
<body>
<?php
use \Michelf\Markdown;
$html = Markdown::defaultTransform('[Test](www.google.com)');
?>
</body>
</html>
在上面的代码中,includetest.php 只是一个测试包含文件,以确保我没有犯错误。该文件包含在输出中,但 MD 链接不包含在输出中。没有出现错误,因此输出如下所示:
输出
This is text from the includetest.php file.
由于我是 PHP 新手,非常感谢任何帮助!
您只是加载解析器,但没有用它做任何事情。你需要一条像
这样的线$my_html = Markdown::defaultTransform($my_text);
...将 Markdown 转换为 HTML。像这样:
<?php
require_once ('subfolder/MarkdownExtra.inc.php');
require_once ('subfolder/includetest.php');
?>
<html>
<body>
<?php echo Markdown::defaultTransform("[Test](www.google.com)"); ?>
</body>
</html>
我以前没用过这个。我只是查看我能找到的文档。