File tree Expand file tree Collapse file tree 3 files changed +70
-4
lines changed Expand file tree Collapse file tree 3 files changed +70
-4
lines changed Original file line number Diff line number Diff line change 10
10
"prefer-stable" : true ,
11
11
"require-dev" : {
12
12
"phpunit/phpunit" : " ^9.5"
13
+ },
14
+ "require" : {
15
+ "ext-mbstring" : " *"
13
16
}
14
17
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @author <julienrajerison5@gmail.com>
4
+ */
5
+
6
+ namespace Julkwel \StringTools ;
7
+
8
+ /**
9
+ * Class StrCleaner.
10
+ */
11
+ class StrCleaner
12
+ {
13
+ /**
14
+ * Clean special char and convert it to lowercase.
15
+ * Param should be a valid string
16
+ *
17
+ * ref : https://stackoverflow.com/a/14114443/10462455
18
+ *
19
+ * @param string $stringToClean
20
+ *
21
+ * @return string
22
+ */
23
+ public static function cleanString (string $ stringToClean ): string
24
+ {
25
+ $ utf8 = [
26
+ '/[áàâãªä]/u ' => 'a ' ,
27
+ '/[ÁÀÂÃÄ]/u ' => 'A ' ,
28
+ '/[ÍÌÎÏ]/u ' => 'I ' ,
29
+ '/[íìîï]/u ' => 'i ' ,
30
+ '/[éèêë]/u ' => 'e ' ,
31
+ '/[ÉÈÊË]/u ' => 'E ' ,
32
+ '/[óòôõºö]/u ' => 'o ' ,
33
+ '/[ÓÒÔÕÖ]/u ' => 'O ' ,
34
+ '/[úùûü]/u ' => 'u ' ,
35
+ '/[ÚÙÛÜ]/u ' => 'U ' ,
36
+ '/ç/ ' => 'c ' ,
37
+ '/Ç/ ' => 'C ' ,
38
+ '/ñ/ ' => 'n ' ,
39
+ '/Ñ/ ' => 'N ' ,
40
+ '/–/ ' => '- ' , // UTF-8 hyphen to "normal" hyphen
41
+ '/[’‘‹›‚]/u ' => ' ' , // Literally a single quote
42
+ '/[“”«»„]/u ' => ' ' , // Double quote
43
+ '/ / ' => ' ' , // non-breaking space (equiv. to 0x160)
44
+ ];
45
+
46
+ return mb_strtolower (preg_replace (array_keys ($ utf8 ), array_values ($ utf8 ), $ stringToClean ));
47
+ }
48
+ }
Original file line number Diff line number Diff line change @@ -17,13 +17,28 @@ class StrCompare
17
17
*
18
18
* @return bool
19
19
*/
20
- public function isStringIsEquals (...$ strings )
20
+ public static function isStringIsEquals (...$ strings ): bool
21
21
{
22
- $ prevString = [];
22
+ $ results = [];
23
23
foreach ($ strings as $ string ) {
24
- $ prevString [$ string ] = $ string ;
24
+ $ results [$ string ] = $ string ;
25
25
}
26
26
27
- return count ($ prevString ) === 1 ;
27
+ return count ($ results ) === 1 ;
28
+ }
29
+
30
+ /**
31
+ * @param ...$strings
32
+ *
33
+ * @return bool
34
+ */
35
+ public static function compareCleanString (...$ strings ): bool
36
+ {
37
+ $ results = [];
38
+ foreach ($ strings as $ string ) {
39
+ $ results [StrCleaner::cleanString ($ string )] = $ string ;
40
+ }
41
+
42
+ return count ($ results ) === 1 ;
28
43
}
29
44
}
You can’t perform that action at this time.
0 commit comments