jdoe
jdoe

Reputation: 333

'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
      `- […]

Upvotes: 3

Views: 862

Answers (2)

Ryan
Ryan

Reputation: 24053

What worked for me was:

composer require michelf/php-markdown
composer dump-autoload

Upvotes: 0

Chay22
Chay22

Reputation: 2894

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

Upvotes: 1

Related Questions