Slugify::slugify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
nc 1
nop 1
dl 0
loc 7
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace KW\Inlagg;
4
5
/**
6
 * Slygifies titles
7
 *
8
 */
9
class Slugify
10
{
11
    /**
12
    * Create a slug of a string, to be used as url.
13
    *
14
    * @param string $str the string to format as slug.
15
    *
16
    * @return str the formatted slug.
17
    */
18
    public function slugify($str)
19
    {
20
        $str = mb_strtolower(trim($str));
21
        $str = str_replace(array('å','ä','ö'), array('a','a','o'), $str);
22
        $str = preg_replace('/[^a-z0-9-]/', '-', $str);
23
        $str = trim(preg_replace('/-+/', '-', $str), '-');
24
        return $str;
25
    }
26
}
27