// 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 );
if ( seems_utf8( $title ) ) { if ( function_exists( 'mb_strtolower'
) ) { $title =
mb_strtolower( $title, 'UTF-8'
);
} $title =
utf8_uri_encode( $title, 200
);
} $title =
strtolower( $title );
if ( 'save' ===
$context ) { // Convert  , &ndash, and &mdash to hyphens.
$title =
str_replace( array
( '%c2%a0', '%e2%80%93', '%e2%80%94'
), '-',
$title );
// Convert  , &ndash, and &mdash HTML entities to hyphens.
$title =
str_replace( array
( ' ', ' ', '–', '–', '—', '—'
), '-',
$title );
// Convert forward slash to hyphen.
$title =
str_replace( '/', '-',
$title );