Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Sanitizes title, replacing whitespace with dashes.
  3.  *
  4.  * Limits the output to alphanumeric characters, underscore (_) and dash (-).
  5.  * Whitespace becomes a dash.
  6.  *
  7.  * @since 1.2.0
  8.  *
  9.  * @param string $title The title to be sanitized.
  10.  * @return string The sanitized title.
  11.  */
  12. function sanitize_title_with_dashes($title) {
  13.     $title = strip_tags($title);
  14.     // Preserve escaped octets.
  15.     $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
  16.     // Remove percent signs that are not part of an octet.
  17.     $title = str_replace('%', '', $title);
  18.     // Restore octets.
  19.     $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
  20.  
  21.     $title = remove_accents($title);
  22.     if (seems_utf8($title)) {
  23.         if (function_exists('mb_strtolower')) {
  24.             $title = mb_strtolower($title, 'UTF-8');
  25.         }
  26.         $title = utf8_uri_encode($title, 200);
  27.     }
  28.  
  29.     $title = strtolower($title);
  30.     $title = preg_replace('/&.+?;/', '', $title); // kill entities
  31.     $title = str_replace('.', '-', $title);
  32.     $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
  33.     $title = preg_replace('/\s+/', '-', $title);
  34.     $title = preg_replace('|-+|', '-', $title);
  35.     $title = trim($title, '-');
  36.  
  37.     return $title;
  38. }