Reading markdown files with parsedown

David Carr

Tutorials PHP & MySQL

Read me files on GitHub are written in Markdown, I wanted to be able to grab the contents of a readme.md file and use it as HTML. This is where Parsedown comes in.

Parsedown is a Markdown parser for PHP, once included converting Markdown to html is as simple as passing the html to it’s text function:

include('parsedown.php');
$html = file_get_contents('https://raw.githubusercontent.com/simple-mvc-framework/framework/master/README.md');
$Parsedown = new Parsedown();
echo $Parsedown->text($html);

That’s it! nice and simple.

For more information on using Parsedown with PHP see this video:

<iframe frameborder="0" height="480" src="https://www.youtube.com/embed/wYZBY8DEikI" width="853"></iframe>

Read articles directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Copyright © 2006 - 2024 DC Blog - All rights reserved.