Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Michelf\Markdown' 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
      `- […]
like image 925
jdoe Avatar asked Feb 28 '26 15:02

jdoe


1 Answers

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);
like image 67
Chay22 Avatar answered Mar 03 '26 05:03

Chay22



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!