Development

/plugins/sfPropelActAsSluggableBehaviorPlugin/lib/sfPropelActAsSluggableBehaviorUtils.class.php

You must first sign up to be able to contribute.

root/plugins/sfPropelActAsSluggableBehaviorPlugin/lib/sfPropelActAsSluggableBehaviorUtils.class.php

Revision 8603, 2.5 kB (checked in by Carl.Vondrick, 4 years ago)

sfPropelActAsSluggableBehaviorPlugin: imported plugin from symfony wiki

Line 
1 <?php
2 /*
3  * This file is part of the sfPropelActAsSluggableBehavior package.
4  *
5  * (c) 2006-2007 Guillermo Rauch (http://devthought.com)
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 class sfPropelActAsSluggableBehaviorUtils
12 {
13   public static function stripText($text, $separator = '-')
14   {
15       $bad = array(
16     'À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å','Ă','ă','Ą','ą',
17     'Ć','ć','Č','č','Ç','ç',
18     'Ď','ď','Đ','đ',
19     'È','è','É','é','Ê','ê','Ë','ë','Ě','ě','Ę','ę',
20     'Ğ','ğ',
21     'Ì','ì','Í','í','Î','î','Ï','ï',
22     'Ĺ','ĺ','Ľ','ľ','Ł','ł',
23     'Ñ','ñ','Ň','ň','Ń','ń',
24     'Ò','ò','Ó','ó','Ô','ô','Õ','õ','Ö','ö','Ø','ø','ő',
25     'Ř','ř','Ŕ','ŕ',
26     'Š','š','Ş','ş','Ś','ś',
27     'Ť','ť','Ť','ť','Ţ','ţ',
28     'Ù','ù','Ú','ú','Û','û','Ü','ü','Ů','ů',
29     'Ÿ','ÿ','ý','Ý',
30     'Ž','ž','Ź','ź','Ż','ż',
31     'Þ','þ','Ð','ð','ß','Œ','œ','Æ','æ','µ',
32     '”','“','‘','’',"'","\n","\r",'_');
33
34     $good = array(
35     'A','a','A','a','A','a','A','a','Ae','ae','A','a','A','a','A','a',
36     'C','c','C','c','C','c',
37     'D','d','D','d',
38     'E','e','E','e','E','e','E','e','E','e','E','e',
39     'G','g',
40     'I','i','I','i','I','i','I','i',
41     'L','l','L','l','L','l',
42     'N','n','N','n','N','n',
43     'O','o','O','o','O','o','O','o','Oe','oe','O','o','o',
44     'R','r','R','r',
45     'S','s','S','s','S','s',
46     'T','t','T','t','T','t',
47     'U','u','U','u','U','u','Ue','ue','U','u',
48     'Y','y','Y','y',
49     'Z','z','Z','z','Z','z',
50     'TH','th','DH','dh','ss','OE','oe','AE','ae','u',
51     '','','','','','','','-');
52
53     // convert special characters
54     $text = str_replace($bad, $good, $text);
55       
56     // convert special characters
57     $text = utf8_decode($text);
58     $text = htmlentities($text);
59     $text = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $text);
60     $text = html_entity_decode($text);
61     
62     $text = strtolower($text);
63
64     // strip all non word chars
65     $text = preg_replace('/\W/', ' ', $text);
66
67     // replace all white space sections with a separator
68     $text = preg_replace('/\ +/', $separator, $text);
69
70     // trim separators
71     $text = trim($text, $separator);
72     //$text = preg_replace('/\-$/', '', $text);
73     //$text = preg_replace('/^\-/', '', $text);
74         
75     return $text;
76   }
77
78  
79 }
80
81 ?>
Note: See TracBrowser for help on using the browser.