public static function sanitizeForUrl($strString = '', $intMaxLength = null)
    {
        if (mb_strlen($strString, QCUBED_ENCODING) > $intMaxLength ||
            (mb_strlen($strString, QCUBED_ENCODING) < $intMaxLength)
        ) {
            $strString = strip_tags($strString);
            $strString = preg_replace('/%([a-fA-F0-9][a-fA-F0-9])/', '--$1--', $strString); // Preserve escaped octets
            $strString = str_replace('%', '', $strString); // Remove percent signs that are not part of an octet
            $strString = preg_replace('/--([a-fA-F0-9][a-fA-F0-9])--/', '%$1', $strString);  // Restore octets

            $strString = QString::removeAccents($strString);

            $strString = mb_convert_case($strString, MB_CASE_LOWER, "UTF-8");
            $strString = preg_replace('/&.+?;/', '', $strString); // Kill entities
            $strString = str_replace('.', '-', $strString);
            $strString = str_replace('::', '-', $strString);
            $strString = preg_replace('/\s+/', '-', $strString); // Remove excess spaces in a string
            $strString = preg_replace('|[\p{Ps}\p{Pe}\p{Pi}\p{Pf}\p{Po}\p{S}\p{Z}\p{C}\p{No}]+|u', '',
                $strString); // Remove separator, control, formatting, surrogate, open/close quotes

            $strString = preg_replace('/-+/', '-', $strString); // Remove excess hyphens
            $strString = trim($strString, '-');

            $strString = mb_substr($strString, 0, $intMaxLength, QCUBED_ENCODING);
            return rtrim($strString, '-'); // When the end of the text remains the hyphen, it is removed.
            //This rtrim() starts implementing at the $intMaxLength.
        } else {
            return $strString;
        }
    }
public static function sanitizeForUrl($strString = '', $intMaxLength = null)
    {
        if (mb_strlen($strString, QCUBED_ENCODING) > $intMaxLength ||
            (mb_strlen($strString, QCUBED_ENCODING) < $intMaxLength)
        ) {
            $strString = strip_tags($strString);
            $strString = preg_replace('/%([a-fA-F0-9][a-fA-F0-9])/', '--$1--', $strString); // Preserve escaped octets
            $strString = str_replace('%', '', $strString); // Remove percent signs that are not part of an octet
            $strString = preg_replace('/--([a-fA-F0-9][a-fA-F0-9])--/', '%$1', $strString);  // Restore octets

            $strString = QString::removeAccents($strString);

            $strString = mb_convert_case($strString, MB_CASE_LOWER, "UTF-8");
            $strString = preg_replace('/&.+?;/', '', $strString); // Kill entities
            $strString = str_replace('.', '-', $strString);
            $strString = str_replace('::', '-', $strString);
            $strString = preg_replace('/\s+/', '-', $strString); // Remove excess spaces in a string
            $strString = preg_replace('|[\p{Ps}\p{Pe}\p{Pi}\p{Pf}\p{Po}\p{S}\p{Z}\p{C}\p{No}]+|u', '',
                $strString); // Remove separator, control, formatting, surrogate, open/close quotes

            $strString = preg_replace('/-+/', '-', $strString); // Remove excess hyphens
            $strString = trim($strString, '-');

            $strString = mb_substr($strString, 0, $intMaxLength, QCUBED_ENCODING);
            return rtrim($strString, '-'); // When the end of the text remains the hyphen, it is removed.
            //This rtrim() starts implementing at the $intMaxLength.
        } else {
            return $strString;
        }
    }
public static function sanitizeForUrl ( $ strString = '' , $ intMaxLength = null ) { if ( mb_strlen ( $ strString , QCUBED_ENCODING ) > $ intMaxLength || ( mb_strlen ( $ strString , QCUBED_ENCODING ) < $ intMaxLength ) ) { $ strString = strip_tags ( $ strString ) ; $ strString = preg_replace ( '/%([a-fA-F0-9][a-fA-F0-9])/' , '--$1--' , $ strString ) ; // Preserve escaped octets $ strString = str_replace ( '%' , '' , $ strString ) ; // Remove percent signs that are not part of an octet $ strString = preg_replace ( '/--([a-fA-F0-9][a-fA-F0-9])--/' , '%$1' , $ strString ) ; // Restore octets $ strString = QString :: removeAccents ( $ strString ) ; $ strString = mb_convert_case ( $ strString , MB_CASE_LOWER , "UTF-8" ) ; $ strString = preg_replace ( '/&.+?;/' , '' , $ strString ) ; // Kill entities $ strString = str_replace ( '.' , '-' , $ strString ) ; $ strString = str_replace ( '::' , '-' , $ strString ) ; $ strString = preg_replace ( '/\s+/' , '-' , $ strString ) ; // Remove excess spaces in a string $ strString = preg_replace ( '|[\p{Ps}\p{Pe}\p{Pi}\p{Pf}\p{Po}\p{S}\p{Z}\p{C}\p{No}]+|u' , '' , $ strString ) ; // Remove separator, control, formatting, surrogate, open/close quotes $ strString = preg_replace ( '/-+/' , '-' , $ strString ) ; // Remove excess hyphens $ strString = trim ( $ strString , '-' ) ; $ strString = mb_substr ( $ strString , 0 , $ intMaxLength , QCUBED_ENCODING ) ; return rtrim ( $ strString , '-' ) ; // When the end of the text remains the hyphen, it is removed. //This rtrim() starts implementing at the $intMaxLength. } else { return $ strString ; } }
Generates a string usable in a URL from any Utf8 encoded string, commonly called a slug.

@param string $strString Input string in utf8
@param integer $intMaxLength the maximum possible length of the string to return. The result will be truncated to this lenghth.

@return string the slug-generated string
Generates a string usable in a URL from any Utf8 encoded string commonly called a slug .