Question: I see web sites that takes any string and replaces all non-alpha numeric characters with a single -

How can I do this?

Answer: 
I use a function like this for czech language:

```
function Slugify($string) {
  $withdiacritic = array_merge(str_split("říšěžťčýůňúěďáéó", 2), array(" ", "/"));
  $woutdiacritic = array_merge(str_split("riseztcyunuedaeo", 1), array("-", "-"));

  $string = mb_strtolower($string);
  $string = str_replace($withdiacritic, $woutdiacritic, ($string));
  $string = preg_replace('/[^a-zA-Z0-9-]/', '-', $string);

  return $string;
}

```

The added value is that it's more readable than converting all non-standard chars to `-`.

**EDIT**

You might also want to add a line like

```
$string = preg_replace('~-{2,}~', '-', $string);

```

to get rid of long `-` sequences.
In PHP?

There might be a better/more efficient pattern, but I just pass my string through this function:

```
function remove_accents($str)
{
    return preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($str, ENT_QUOTES, 'UTF-8'));
}

```