Reputation: 333
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
Reputation: 24053
What worked for me was:
composer require michelf/php-markdown
composer dump-autoload
Upvotes: 0
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