回答編集履歴

3

誤字の修正

2017/01/10 09:17

投稿

motuo
motuo

スコア3027

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  //(あえてスラッシュは正規表現の検索対象としていません。)
24
24
 
25
- $a = preg_match('#[\\\\:?<>|]|\.{1,2}/#', $test,$m);
25
+ $a = preg_match('#[\\\:?<>|]|\.{1,2}/#', $test,$m);
26
26
 
27
27
  ```
28
28
 

2

正規表現による記述を追記

2017/01/10 09:17

投稿

motuo
motuo

スコア3027

test CHANGED
@@ -9,6 +9,20 @@
9
9
  return strlen($s) !== strlen(mb_convert_encoding(mb_convert_encoding($s,'SJIS','UTF-8'),'UTF-8','SJIS'));
10
10
 
11
11
  }
12
+
13
+ ```
14
+
15
+ ###正規表現によるチェック
16
+
17
+ ```php
18
+
19
+ $test = 'a\\b';
20
+
21
+ //この正規表現では、「\,:,?,<,>,|」と「./」と「../」を検索します。
22
+
23
+ //(あえてスラッシュは正規表現の検索対象としていません。)
24
+
25
+ $a = preg_match('#[\\\\:?<>|]|\.{1,2}/#', $test,$m);
12
26
 
13
27
  ```
14
28
 
@@ -68,6 +82,6 @@
68
82
 
69
83
  }
70
84
 
85
+ ```
71
86
 
72
87
 
73
- ```

1

回答内容を追記

2017/01/10 08:55

投稿

motuo
motuo

スコア3027

test CHANGED
@@ -11,3 +11,63 @@
11
11
  }
12
12
 
13
13
  ```
14
+
15
+ ###追記
16
+
17
+ ```php
18
+
19
+ /**
20
+
21
+ * 機種依存文字チェック
22
+
23
+ * @param type $text
24
+
25
+ * @return boolean
26
+
27
+ */
28
+
29
+ function platform_dependent_characters_filter($text) {
30
+
31
+
32
+
33
+ mb_regex_encoding('UTF-8');
34
+
35
+ //$pdcでチェックの対象とする文字を設定
36
+
37
+ $pdc = '⑩⑪⑫⑬⑭⑯⑰⑱⑲⑳';
38
+
39
+ $pdc_array = Array();
40
+
41
+ $pdc_text = str_replace(array("\r\n", "\n", "\r"), '', $text);
42
+
43
+ //チェック対象を配列化
44
+
45
+ while ($iLen = mb_strlen($pdc, 'UTF-8')) {
46
+
47
+ array_push($pdc_array, mb_substr($pdc, 0, 1, 'UTF-8'));
48
+
49
+ $pdc = mb_substr($pdc, 1, $iLen, 'UTF-8');
50
+
51
+ }
52
+
53
+
54
+
55
+ //特殊文字が無いかどうかチェックする
56
+
57
+ foreach ($pdc_array as $value) {
58
+
59
+ if (preg_match("/(" . $value . ")/", $pdc_text)) {
60
+
61
+ return true;
62
+
63
+ }
64
+
65
+ }
66
+
67
+ return false;
68
+
69
+ }
70
+
71
+
72
+
73
+ ```