1function hyphenize($string) {
2 $dict = array(
3 "I'm" => "I am",
4 "thier" => "their",
5 // Add your own replacements here
6 );
7 return strtolower(
8 preg_replace(
9 array( '#[\\s-]+#', '#[^A-Za-z0-9. -]+#' ),
10 array( '-', '' ),
11 // the full cleanString() can be downloaded from http://www.unexpectedit.com/php/php-clean-string-of-utf8-chars-convert-to-similar-ascii-char
12 cleanString(
13 str_replace( // preg_replace can be used to support more complicated replacements
14 array_keys($dict),
15 array_values($dict),
16 urldecode($string)
17 )
18 )
19 )
20 );
21}
22
23function cleanString($text) {
24 $utf8 = array(
25 '/[áàâãªä]/u' => 'a',
26 '/[ÁÀÂÃÄ]/u' => 'A',
27 '/[ÍÌÎÏ]/u' => 'I',
28 '/[íìîï]/u' => 'i',
29 '/[éèêë]/u' => 'e',
30 '/[ÉÈÊË]/u' => 'E',
31 '/[óòôõºö]/u' => 'o',
32 '/[ÓÒÔÕÖ]/u' => 'O',
33 '/[úùûü]/u' => 'u',
34 '/[ÚÙÛÜ]/u' => 'U',
35 '/ç/' => 'c',
36 '/Ç/' => 'C',
37 '/ñ/' => 'n',
38 '/Ñ/' => 'N',
39 '/–/' => '-', // UTF-8 hyphen to "normal" hyphen
40 '/[’‘‹›‚]/u' => ' ', // Literally a single quote
41 '/[“”«»„]/u' => ' ', // Double quote
42 '/ /' => ' ', // nonbreaking space (equiv. to 0x160)
43 );
44 return preg_replace(array_keys($utf8), array_values($utf8), $text);
45}
46