回答編集履歴
2
余計なコメントを削除
test
CHANGED
@@ -140,8 +140,6 @@
|
|
140
140
|
|
141
141
|
$explodeUrlList = explode(',', $url);
|
142
142
|
|
143
|
-
//var_dump($explodeUrlList);
|
144
|
-
|
145
143
|
$getInfo['url'][] = $explodeUrlList[0];
|
146
144
|
|
147
145
|
$getInfo['title'][] = $explodeUrlList[1];
|
1
回答を追記
test
CHANGED
@@ -103,3 +103,131 @@
|
|
103
103
|
)
|
104
104
|
|
105
105
|
```
|
106
|
+
|
107
|
+
# 何回目のforeachでうまくいったかをカウントする方法
|
108
|
+
|
109
|
+
```php
|
110
|
+
|
111
|
+
<?php
|
112
|
+
|
113
|
+
//ドメイン
|
114
|
+
|
115
|
+
$domainList = array("sample.jp","sample.co.jp","sample.com");
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
//URL sample.co.jp は該当しない 他は2つずつ検知されるようになっている。
|
120
|
+
|
121
|
+
$urlList = array("http://sample.jp/aaa.html,sample.jpのサイトタイトル1","http://sample.com/aaa.html,sample.comのサイトタイトル1","http://sample.org/aaa.html,sample.orgのサイトタイトル1","http://sample.jp/bbb.html,sample.jpのサイトタイトル2","sample.com/bbb.html,sample.comのサイトタイトル2");
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
$getInfo = array();
|
126
|
+
|
127
|
+
foreach ($domainList as $domain) {
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
$found = FALSE;
|
132
|
+
|
133
|
+
foreach ($urlList as $key => $url) {
|
134
|
+
|
135
|
+
if (strpos($url, $domain) !== FALSE) {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
//キーワード検索結果の分類 →カンマで句切られているため
|
140
|
+
|
141
|
+
$explodeUrlList = explode(',', $url);
|
142
|
+
|
143
|
+
//var_dump($explodeUrlList);
|
144
|
+
|
145
|
+
$getInfo['url'][] = $explodeUrlList[0];
|
146
|
+
|
147
|
+
$getInfo['title'][] = $explodeUrlList[1];
|
148
|
+
|
149
|
+
$getInfo['count'][] = $key;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
$found = TRUE;
|
154
|
+
|
155
|
+
break;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
if (!$found) {
|
164
|
+
|
165
|
+
$getInfo['url'][] = '該当なし';
|
166
|
+
|
167
|
+
$getInfo['title'][] = '該当なし';
|
168
|
+
|
169
|
+
$getInfo['count'][] = '該当なし';
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
print_r($getInfo);
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
実行結果
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
Array
|
186
|
+
|
187
|
+
(
|
188
|
+
|
189
|
+
[url] => Array
|
190
|
+
|
191
|
+
(
|
192
|
+
|
193
|
+
[0] => http://sample.jp/aaa.html
|
194
|
+
|
195
|
+
[1] => 該当なし
|
196
|
+
|
197
|
+
[2] => http://sample.com/aaa.html
|
198
|
+
|
199
|
+
)
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
[title] => Array
|
204
|
+
|
205
|
+
(
|
206
|
+
|
207
|
+
[0] => sample.jpのサイトタイトル1
|
208
|
+
|
209
|
+
[1] => 該当なし
|
210
|
+
|
211
|
+
[2] => sample.comのサイトタイトル1
|
212
|
+
|
213
|
+
)
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
[count] => Array
|
218
|
+
|
219
|
+
(
|
220
|
+
|
221
|
+
[0] => 0
|
222
|
+
|
223
|
+
[1] => 該当なし
|
224
|
+
|
225
|
+
[2] => 1
|
226
|
+
|
227
|
+
)
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
)
|
232
|
+
|
233
|
+
```
|