src/DataHandling.php
public static function sanitizeUrlParts($urlPartOrUrlParts, ...$additionalUrlParts)
    {
        if (is_array($urlPartOrUrlParts)) {
            $urlParts = $urlPartOrUrlParts;
        } else {
            $urlParts = array_merge([$urlPartOrUrlParts], $additionalUrlParts);
        }

        $sanitizedUrlParts = [];
        foreach ($urlParts as $urlPart) {
            $urlPart = self::sanitizeString($urlPart);

            // Replace accented characters for their regular counterparts
            $urlPart = str_replace(array_keys(self::ACCENTED_CHARACTERS), array_values(self::ACCENTED_CHARACTERS), $urlPart);

            // Collapse spaces, dashes and underscores into single dashes
            $urlPart = preg_replace("/[\s-_]+/", "-", $urlPart);

            $urlPart = strtolower($urlPart);

            // Remove any leftover invalid characters
            $urlPart = preg_replace("/[^a-z0-9\\-\\.]/", "", $urlPart);

            // Trim possibly existing dashes at start and end of string
            $urlPart = trim($urlPart, "-");

            $sanitizedUrlParts[] = $urlPart;
        }

        return implode("/", $sanitizedUrlParts);
    }
public static function sanitizeUrlParts($urlPartOrUrlParts, ...$additionalUrlParts)
    {
        if (is_array($urlPartOrUrlParts)) {
            $urlParts = $urlPartOrUrlParts;
        } else {
            $urlParts = array_merge([$urlPartOrUrlParts], $additionalUrlParts);
        }

        $sanitizedUrlParts = [];
        foreach ($urlParts as $urlPart) {
            $urlPart = self::sanitizeString($urlPart);

            // Replace accented characters for their regular counterparts
            $urlPart = str_replace(array_keys(self::ACCENTED_CHARACTERS), array_values(self::ACCENTED_CHARACTERS), $urlPart);

            // Collapse spaces, dashes and underscores into single dashes
            $urlPart = preg_replace("/[\s-_]+/", "-", $urlPart);

            $urlPart = strtolower($urlPart);

            // Remove any leftover invalid characters
            $urlPart = preg_replace("/[^a-z0-9\\-\\.]/", "", $urlPart);

            // Trim possibly existing dashes at start and end of string
            $urlPart = trim($urlPart, "-");

            $sanitizedUrlParts[] = $urlPart;
        }

        return implode("/", $sanitizedUrlParts);
    }
public static function sanitizeUrlParts ( $ urlPartOrUrlParts , ... $ additionalUrlParts ) { if ( is_array ( $ urlPartOrUrlParts ) ) { $ urlParts = $ urlPartOrUrlParts ; } else { $ urlParts = array_merge ( [ $ urlPartOrUrlParts ] , $ additionalUrlParts ) ; } $ sanitizedUrlParts = [ ] ; foreach ( $ urlParts as $ urlPart ) { $ urlPart = self :: sanitizeString ( $ urlPart ) ; // Replace accented characters for their regular counterparts $ urlPart = str_replace ( array_keys ( self :: ACCENTED_CHARACTERS ) , array_values ( self :: ACCENTED_CHARACTERS ) , $ urlPart ) ; // Collapse spaces, dashes and underscores into single dashes $ urlPart = preg_replace ( "/[\s-_]+/" , "-" , $ urlPart ) ; $ urlPart = strtolower ( $ urlPart ) ; // Remove any leftover invalid characters $ urlPart = preg_replace ( "/[^a-z0-9\\-\\.]/" , "" , $ urlPart ) ; // Trim possibly existing dashes at start and end of string $ urlPart = trim ( $ urlPart , "-" ) ; $ sanitizedUrlParts [ ] = $ urlPart ; } return implode ( "/" , $ sanitizedUrlParts ) ; }
Sanitize, or SEOify url part.
Will result in a string with only dashes, dots and alphanumeric characters.
Arguments are joined by slashes.
If an array of parts is given as the first argument, each one will be processed and returned as one string with slashes between parts.

@param string|string[] $urlPartOrUrlParts An array of parts or a single part.
@param string[] $additionalUrlParts Additional url parts, if the first argument is not an array.
@return string
Sanitize or SEOify url part . Will result in a string with only dashes dots and alphanumeric characters . Arguments are joined by slashes . If an array of parts is given as the first argument each one will be processed and returned as one string with slashes between parts .