<?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/