urlify string / create a slug

revision c7b1a56df6bb745bd88c3b9471345a16a12d5d1b

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(trim($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