Пример #1
0
function get_uri($title)
{
    $title = strip_tags($title);
    // Preserve escaped octets.
    //$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
    // Remove percent signs that are not part of an octet.
    //$title = str_replace('%', '', $title);
    // Restore octets.
    //$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    $title = remove_accents($title);
    $title = mb_strtolower($title, 'UTF-8');
    $title = preg_replace('/&.+?;/', '', $title);
    // kill entities
    //$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
    $title = preg_replace('/[\\W¿¡]+/u', '-', $title);
    $title = preg_replace('/[^a-z0-9,;:\\]\\[\\(\\)\\. _-]/', '', $title);
    $title = preg_replace('/\\.+$|^\\.+/', '', $title);
    $title = preg_replace('/\\.+-|-\\.+/', '-', $title);
    $title = preg_replace('|-+|', '-', $title);
    $title = remove_shorts($title);
    $words = preg_split('/-/', $title);
    $uri = '';
    foreach ($words as $word) {
        if (!empty($word) && $word != '-' && strlen($word) + strlen($uri) < 65) {
            $uri .= $word . '-';
        }
    }
    if (strlen($uri) < 5) {
        // Just in case if there were no short words
        $uri = substr($title, 0, 50);
    }
    $uri = trim($uri, '-');
    return $uri;
}
Пример #2
0
function get_uri($title)
{
    $title = strip_tags($title);
    // Preserve escaped octets.
    //$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
    // Remove percent signs that are not part of an octet.
    //$title = str_replace('%', '', $title);
    // Restore octets.
    //$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    $title = mb_strtolower($title, 'UTF-8');
    $title = strtolower($title);
    $title = remove_accents($title);
    $title = preg_replace('/&.+?;/', '', $title);
    // kill entities
    //$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
    $title = preg_replace('/[^a-z0-9,;:\\]\\[\\(\\)\\. _-]/', '', $title);
    $title = preg_replace('/[\\s,;:\\]\\[\\(\\)]+/', '-', $title);
    $title = preg_replace('/\\.+$|^\\.+/', '', $title);
    $title = preg_replace('/\\.+-|-\\.+/', '-', $title);
    $title = preg_replace('|-+|', '-', $title);
    $title = remove_shorts($title);
    $title = trim($title, '-');
    return substr($title, 0, 70);
}