How to Convert Markdown to HTML in PHP
Writing Markdown is certainly a lot easier than writing HTML, but you still need to convert Markdown elements into HTML elements before displaying that information on a web page.
Thankfully, you can make your Markdown to HTML conversions at scale implementing the free-to-use API provided below. This API will quickly convert your .md (Markdown) files into an HTML string — simple as that. You’ll just need a free-tier API (visit our website to get one) to authenticate your request, which will provide a limit of 800 API calls per month and zero additional commitments.
To use this API, first run the following command to install the PHP SDK:
composer require cloudmersive/cloudmersive_document_convert_api_client
After that, complete your API call with the remaining code examples:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\ConvertWebApi(
new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->convertWebMdToHtml($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertWebApi->convertWebMdToHtml: ', $e->getMessage(), PHP_EOL;
}
?>
And that’s all there is to it!