Home Account

Pandoc hash slugs in PHP

2016-03-13 19:10 dennis iversen

In a project I needed to replicate the way pandoc makes hash slugs in HTML documents. I came up with this method:

    function generatePandocLink ($title) {

        $title = preg_replace("/[^[:alnum:][:space:]]/u", '', $title);
        $title = str_replace(' ', '-', $title);
        $title = trim($title, '-');
        $title = mb_strtolower($title, 'UTF8');
        return $title;

    }

Worked perfect.

This page has been requested 4654 times