Skip to content
Advertisement

Failed to markdown parser function in php using regex

Let’s write a simple markdown parser function that will take in a single line of markdown and be translated into the appropriate HTML. To keep it simple, we’ll support only one feature of markdown in atx syntax: headers.

Headers are designated by (1-6) hashes followed by a space, followed by text. The number of hashes determines the header level of the HTML output.

Examples

JavaScript

My code :

JavaScript

its not working as failed test case :

JavaScript

Advertisement

Answer

What i understood is you want to limit your markdown conversion to a range of 1-6 depth for your title.

Give a try to this code :

JavaScript

I only add a condition to check if your number of hashtag is in range of 1 until 6if (in_array($h_num, range(1, 6), true)) {

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement