Pandoc hash slugs in PHP

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 viewed 581 times. First hit: 13-Mar-2016 17:12:16
Share email, Google+, Twitter, Facebook.
comments powered by Disqus
Table