回答編集履歴

1

2015/02/05 03:12

投稿

hogehogehoge
hogehogehoge

スコア165

test CHANGED
@@ -5,8 +5,6 @@
5
5
  まず1つ目が、preg_grep()関数を使った方法です。コード例と出力結果は下記になります。
6
6
 
7
7
 
8
-
9
- ```lang-<ここに言語を入力>
10
8
 
11
9
  $search_word = array (
12
10
 
@@ -40,21 +38,17 @@
40
38
 
41
39
  )
42
40
 
43
- ```
44
-
45
41
 
46
42
 
47
43
  preg_grep()関数の詳しい説明は、PHPマニュアルを参照して下さい。
48
44
 
49
- [http://www.php.net/manual/ja/function.preg-grep.php](http://www.php.net/manual/ja/function.preg-grep.php)
45
+ http://www.php.net/manual/ja/function.preg-grep.php
50
46
 
51
47
 
52
48
 
53
49
  次に2つ目が、preg_match()関数とarray_reduce()関数を使う方法です。コード例と出力結果は下記になります。
54
50
 
55
51
 
56
-
57
- ```lang-<ここに言語を入力>
58
52
 
59
53
  $search_word = array (
60
54
 
@@ -72,13 +66,13 @@
72
66
 
73
67
  function _matchewords($m, $str){
74
68
 
75
- if(preg_match('/^hello (\w+)/i', $str, $matches)){
69
+ if(preg_match('/^hello (\w+)/i', $str, $matches)){
76
70
 
77
- $m[] = $matches[1];
71
+ $m[] = $matches[1];
78
72
 
79
- }
73
+ }
80
74
 
81
- return $m;
75
+ return $m;
82
76
 
83
77
  }
84
78
 
@@ -102,15 +96,13 @@
102
96
 
103
97
  )
104
98
 
105
- ```
106
-
107
99
 
108
100
 
109
101
  preg_match()関数とarray_reduce()関数の詳しい説明は、PHPマニュアルを参照して下さい。
110
102
 
111
- [http://www.php.net/manual/ja/function.preg-match.php](http://www.php.net/manual/ja/function.preg-match.php)
103
+ http://www.php.net/manual/ja/function.preg-match.php
112
104
 
113
- [http://www.php.net/manual/ja/function.array-reduce.php](http://www.php.net/manual/ja/function.array-reduce.php)
105
+ http://www.php.net/manual/ja/function.array-reduce.php
114
106
 
115
107
 
116
108
 
@@ -118,23 +110,19 @@
118
110
 
119
111
 
120
112
 
121
- ```lang-<ここに言語を入力>
122
-
123
113
  $matches = array ();
124
114
 
125
115
 
126
116
 
127
117
  foreach ($search_word as $str){
128
118
 
129
- if (preg_match('/^hello (\w+)/i', $str, $m)){
119
+ if (preg_match('/^hello (\w+)/i', $str, $m)){
130
120
 
131
- $matches[] = $m[1];
121
+ $matches[] = $m[1];
132
-
133
- }
134
122
 
135
123
  }
136
124
 
137
- ```
125
+ }
138
126
 
139
127
 
140
128