jdoe jdoe - 3 months ago 22
Markdown Question

'Michelf\Mardown' class not found

I would like to use 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";


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:

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

Answer

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);