2

I want to use Michel Fortin's PHP Markdown parser. The new style requires the user to set up a PSR-0-compatible autoloader. However, the instructions also state:

If you don’t want to use autoloading you can do a classic require_once to manually include the files prior use instead.

Unfortunately there are no instructions on simply using require_once. I don't want to use an autoloader, how can I use this Markdown parser to parse my string of Markdown?


EDIT: Also, is it possible to use the parser with require_once inside a function (and outside the global scope)? The problem with use is it must be used globally which seems to make require_once required in the global scope. My preference is to only require_once if necessary in a function and outside the global scope.

1 Answers1

3

There's really only two files you might need to require.

For regular Mardown:

require_once '/path/to/code/Michelf/Markdown.php';

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

Or for Markdown Extra:

require_once '/path/to/code/Michelf/MarkdownExtra.php';

$my_html = \Michelf\MarkdownExtra::defaultTransform($my_text);
jnrbsn
  • 2,498
  • 1
  • 18
  • 25
  • Thanks. I had `require_once` and `use` inside a function which was causing my problem. Is there any way to avoid `use \Michelf\Markdown;` altogether here so I can `require_once` inside a function? My preference is to `require_once` only if necessary and that means putting `require_once` in a function outside the global scope which apparently I can't do because it must be declared before `use` which must be in the global scope. –  Oct 21 '13 at 05:06
  • You can use the fully qualified names of the classes. I've edited my answer above to reflect that. – jnrbsn Oct 21 '13 at 05:35