jdoe jdoe - 1 year ago 97
Markdown Question

'Michelf\Mardown' class not found

I would like to use Michelf Markdown Parser

ini_set('display_errors', 'On');

$my_text = " a";

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

echo "end";

Unfortunately, it doesn't work. I got the error:

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

I searched a bit, found that someone had a similar issue. But adding 'Michelf\' didn't change anything:

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

I got the same error message.

This is my file tree:

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

Answer Source

The package supposed you use an autoloader if you're using like right that way. What I meant is composer. I could be wrong but, if you are using composer, path of the library should be laying under /vendor directory

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

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

Or if you're not with composer, readme of the library is telling you how to use it here

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

$my_text = 'a';
$my_html = Markdown::defaultTransform($my_text);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download