回答編集履歴
2
余計なコメントを削除
answer
CHANGED
@@ -69,7 +69,6 @@
|
|
69
69
|
|
70
70
|
//キーワード検索結果の分類 →カンマで句切られているため
|
71
71
|
$explodeUrlList = explode(',', $url);
|
72
|
-
//var_dump($explodeUrlList);
|
73
72
|
$getInfo['url'][] = $explodeUrlList[0];
|
74
73
|
$getInfo['title'][] = $explodeUrlList[1];
|
75
74
|
$getInfo['count'][] = $key;
|
1
回答を追記
answer
CHANGED
@@ -50,4 +50,68 @@
|
|
50
50
|
)
|
51
51
|
|
52
52
|
)
|
53
|
+
```
|
54
|
+
# 何回目のforeachでうまくいったかをカウントする方法
|
55
|
+
```php
|
56
|
+
<?php
|
57
|
+
//ドメイン
|
58
|
+
$domainList = array("sample.jp","sample.co.jp","sample.com");
|
59
|
+
|
60
|
+
//URL sample.co.jp は該当しない 他は2つずつ検知されるようになっている。
|
61
|
+
$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");
|
62
|
+
|
63
|
+
$getInfo = array();
|
64
|
+
foreach ($domainList as $domain) {
|
65
|
+
|
66
|
+
$found = FALSE;
|
67
|
+
foreach ($urlList as $key => $url) {
|
68
|
+
if (strpos($url, $domain) !== FALSE) {
|
69
|
+
|
70
|
+
//キーワード検索結果の分類 →カンマで句切られているため
|
71
|
+
$explodeUrlList = explode(',', $url);
|
72
|
+
//var_dump($explodeUrlList);
|
73
|
+
$getInfo['url'][] = $explodeUrlList[0];
|
74
|
+
$getInfo['title'][] = $explodeUrlList[1];
|
75
|
+
$getInfo['count'][] = $key;
|
76
|
+
|
77
|
+
$found = TRUE;
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!$found) {
|
83
|
+
$getInfo['url'][] = '該当なし';
|
84
|
+
$getInfo['title'][] = '該当なし';
|
85
|
+
$getInfo['count'][] = '該当なし';
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
print_r($getInfo);
|
90
|
+
```
|
91
|
+
実行結果
|
92
|
+
```
|
93
|
+
Array
|
94
|
+
(
|
95
|
+
[url] => Array
|
96
|
+
(
|
97
|
+
[0] => http://sample.jp/aaa.html
|
98
|
+
[1] => 該当なし
|
99
|
+
[2] => http://sample.com/aaa.html
|
100
|
+
)
|
101
|
+
|
102
|
+
[title] => Array
|
103
|
+
(
|
104
|
+
[0] => sample.jpのサイトタイトル1
|
105
|
+
[1] => 該当なし
|
106
|
+
[2] => sample.comのサイトタイトル1
|
107
|
+
)
|
108
|
+
|
109
|
+
[count] => Array
|
110
|
+
(
|
111
|
+
[0] => 0
|
112
|
+
[1] => 該当なし
|
113
|
+
[2] => 1
|
114
|
+
)
|
115
|
+
|
116
|
+
)
|
53
117
|
```
|