urlify string / create a slug

revision 73c6c1f4b2accedb036a40f61a08f8775c037f29

raw

phork0.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
function urlify($str)
{
    $str = mb_strtolower($str);
    $str = str_replace(
        ['ä', 'ö', 'ü', 'ß', ' '],
        ['ae', 'oe', 'ue', 'ss', '-'],
        $str
    );
    $str = preg_replace('#[^-a-z0-9]#', '', $str);
    $str = str_replace('--', '-', $str);
 
    $str = implode('-', array_unique(explode('-', $str)));
 
    return $str;
}
 

History