php - 未找到“Michelf\Markdown”类

标签 php class markdown

我想使用 Michelf Markdown Parser

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);

$my_text = " a";

use \Michelf\Markdown;
$my_html = Markdown::defaultTransform($my_text);

echo "end";

不幸的是,它不起作用。我得到了错误:

Fatal error: Uncaught Error: Class 'Michelf\Markdown' not found in /path/to/index.php:8 Stack trace: #0 {main} thrown in /path/to/index.php on line 8

我搜索了一下,发现有人had a similar issue .但是添加“Michelf\”并没有改变任何东西:

$my_html = \Michelf\Markdown::defaultTransform($my_text);

我得到了同样的错误信息。

这是我的文件树:

/path/to/
  |- index.php
  `- Michelf/
      |- Markdown.php
      |- MarkdownInterface.php
      `- […]

最佳答案

如果您以正确的方式使用,则该软件包假定您使用了自动加载器。我的意思是composer .我可能是错的,但是,如果你使用的是 composer,库的路径应该放在 /vendor 目录下

require_once 'vendor/autoload.php';
use Michelf\Markdown;

$my_text = 'a';
$my_html = Markdown::defaultTransform($my_text);

或者,如果您不使用 composer,库的自述文件会告诉您如何使用它 here

require_once 'Michelf/Markdown.inc.php';
use Michelf\Markdown;

$my_text = 'a';
$my_html = Markdown::defaultTransform($my_text);

关于php - 未找到“Michelf\Markdown”类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911965/

相关文章:

html - 如何使用 Nokogiri 将 HTML 转换为 Markdown?

github - 从 Github 的 Wiki 页面下载 `.md` 文件的干净方法

html - 如何在html内的markdown中使用脚注?

php - 如何在 Symfony 4 的 .env 文件中配置 MAILER_URL 以使用 Swift_Mailer 通过 sendmail 发送电子邮件?

php - 什么是 MediaWiki 中 AuthPlugin 上下文中的 "domain"?

JAVA类空值

c++ - 如何将 C++ 关键字 "this"与成员函数 "operator="一起使用?

php - 将 PHP 变量转换为 bash 变量

php - 向多个表中插入一个值

python - 为什么 Python 的 re 模块在这个方法中不起作用?