回答編集履歴
4
微修正
test
CHANGED
@@ -46,6 +46,8 @@
|
|
46
46
|
|
47
47
|
'piyo?',
|
48
48
|
|
49
|
+
'hage/',
|
50
|
+
|
49
51
|
];
|
50
52
|
|
51
53
|
|
@@ -54,7 +56,9 @@
|
|
54
56
|
|
55
57
|
function evilsenser(array $ng_words, string $original_word){
|
56
58
|
|
57
|
-
$ng_words = array_map('preg_quote', $ng_words);//指摘により追記
|
59
|
+
// $ng_words = array_map('preg_quote', $ng_words);//指摘により追記
|
60
|
+
|
61
|
+
$ng_words = array_map(function($a){return preg_quote($a, '/');}, $ng_words);//指摘により再修正
|
58
62
|
|
59
63
|
$bad_words = '/' . implode('|',$ng_words) . '/u';
|
60
64
|
|
@@ -78,6 +82,8 @@
|
|
78
82
|
|
79
83
|
'tepiyo?st',
|
80
84
|
|
85
|
+
'tehage/st',
|
86
|
+
|
81
87
|
];
|
82
88
|
|
83
89
|
|
3
修正
test
CHANGED
@@ -44,6 +44,8 @@
|
|
44
44
|
|
45
45
|
'fuga',
|
46
46
|
|
47
|
+
'piyo?',
|
48
|
+
|
47
49
|
];
|
48
50
|
|
49
51
|
|
@@ -51,6 +53,8 @@
|
|
51
53
|
|
52
54
|
|
53
55
|
function evilsenser(array $ng_words, string $original_word){
|
56
|
+
|
57
|
+
$ng_words = array_map('preg_quote', $ng_words);//指摘により追記
|
54
58
|
|
55
59
|
$bad_words = '/' . implode('|',$ng_words) . '/u';
|
56
60
|
|
@@ -70,9 +74,13 @@
|
|
70
74
|
|
71
75
|
'testfuga',
|
72
76
|
|
77
|
+
'tepiyost',
|
78
|
+
|
79
|
+
'tepiyo?st',
|
80
|
+
|
73
81
|
];
|
74
82
|
|
75
|
-
|
83
|
+
|
76
84
|
|
77
85
|
foreach ($test_words as $value) {
|
78
86
|
|
2
追記
test
CHANGED
@@ -27,3 +27,61 @@
|
|
27
27
|
```
|
28
28
|
|
29
29
|
とか、してやるときれいになる気がする。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
**追記**
|
34
|
+
|
35
|
+
まとめてみた。
|
36
|
+
|
37
|
+
```php
|
38
|
+
|
39
|
+
<?php
|
40
|
+
|
41
|
+
$ng_words = [
|
42
|
+
|
43
|
+
'hoge',
|
44
|
+
|
45
|
+
'fuga',
|
46
|
+
|
47
|
+
];
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
function evilsenser(array $ng_words, string $original_word){
|
54
|
+
|
55
|
+
$bad_words = '/' . implode('|',$ng_words) . '/u';
|
56
|
+
|
57
|
+
return (preg_match($bad_words, $original_word) === 1);
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
$test_words = [
|
64
|
+
|
65
|
+
'test',
|
66
|
+
|
67
|
+
'hoge',
|
68
|
+
|
69
|
+
'hogetest',
|
70
|
+
|
71
|
+
'testfuga',
|
72
|
+
|
73
|
+
];
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
foreach ($test_words as $value) {
|
78
|
+
|
79
|
+
echo $value . ':';
|
80
|
+
|
81
|
+
var_export(evilsenser($ng_words, $value));
|
82
|
+
|
83
|
+
echo PHP_EOL;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
```
|
1
微修正
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
```
|
24
24
|
|
25
|
-
$bat_words = '/' . implode('|',$ng_words) . '/';
|
25
|
+
$bat_words = '/' . implode('|',$ng_words) . '/u';
|
26
26
|
|
27
27
|
```
|
28
28
|
|