Slug

<?php

namespace Utils\Slug;

Class Slug {

    public static function slugify($url, $maxLength = 500) {

        $S = array('/ą/', '/ż/', '/ź/', '/ę/', '/ć/', '/ń/', '/ó/', '/ł/', '/ś/', '/Ą/', '/Ż/', '/Ź/', '/Ę/', '/Ć/', '/Ń/', '/Ó/', '/Ł/', '/Ś/');
        $R = array('a', 'z', 'z', 'e', 'c', 'n', 'o', 'l', 's', 'A', 'Z', 'Z', 'E', 'C', 'N', 'O', 'L', 'S');
        $url = preg_replace($S, $R, $url);
        $url = strtolower(trim($url));
        $url = preg_replace('/\?/', '', $url);
        $url = preg_replace('/[^a-z0-9-]/', '-', $url);
        $url = preg_replace('/-+/', "-", $url);
        $url = substr($url, 0, $maxLength);
        return $url;
    }

}
Komentarze wyłączone