質問するログイン新規登録

質問編集履歴

4

質問されたことに対して修正

2016/07/14 10:31

投稿

igaiga
igaiga

スコア144

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,7 @@
6
6
  よろしくお願いします。
7
7
 
8
8
  ```
9
+ <?php
9
10
  header("Content-Type: text/html; charset=UTF-8");
10
11
  unlink("list.txt");
11
12
  require_once( dirname(__FILE__) . '/wp-load.php' );
@@ -27,4 +28,30 @@
27
28
 
28
29
  $xml2 = simplexml_load_file($detail);
29
30
  $data2 = get_object_vars($xml2);
31
+ foreach ((array)$data2['room'] as $url2) {
32
+ $building_cd = $url2->real_building_name;//物件ID
33
+ //テキストファイルに保存
34
+ $fp = fopen('list.txt', 'a');
35
+ if ($fp){
36
+ if (flock($fp, LOCK_EX)){
37
+ if (fwrite($fp, $building_cd."\n") === FALSE){
38
+ print('ファイル書き込みに失敗しました<br>');
39
+ }
40
+ flock($fp, LOCK_UN);
41
+ }else{
42
+ print('ファイルロックに失敗しました<br>');
43
+ }
44
+ }
45
+ }
46
+ }
47
+ $flag = fclose($fp);
48
+
49
+ if ($flag){
50
+ print('URLリストを「list.txt」に保存しました');
51
+ }else{
52
+ print('クローズに失敗しました');
53
+ }
54
+ echo "全て取り込み完了しました";
55
+ ?>
56
+
30
57
  ```

3

追記

2016/07/14 10:31

投稿

igaiga
igaiga

スコア144

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,9 @@
6
6
  よろしくお願いします。
7
7
 
8
8
  ```
9
+ header("Content-Type: text/html; charset=UTF-8");
10
+ unlink("list.txt");
11
+ require_once( dirname(__FILE__) . '/wp-load.php' );
9
12
  $xml = simplexml_load_file('http://hoge.jp/city/?key=000&pref_cd=14');
10
13
  $data = get_object_vars($xml);
11
14
 

2

誤字

2016/07/14 10:28

投稿

igaiga
igaiga

スコア144

title CHANGED
File without changes
body CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  for($i = 0; $i < $results_available; $i++){
16
16
  if($i = 0){
17
- $detail = "http://hoge.jp/room/?key=QYGFU8OP&city_cd=" . $url->code;
17
+ $detail = "http://hoge.jp/room/?key=000&city_cd=" . $url->code;
18
18
  } else {
19
19
  $results_i = ($i*50)+1;
20
20
  $results_count = "&start=" . $results_i . "&count=50";

1

質問が来たので

2016/07/14 09:33

投稿

igaiga
igaiga

スコア144

title CHANGED
File without changes
body CHANGED
@@ -6,8 +6,22 @@
6
6
  よろしくお願いします。
7
7
 
8
8
  ```
9
+ $xml = simplexml_load_file('http://hoge.jp/city/?key=000&pref_cd=14');
9
- $results = 5;
10
+ $data = get_object_vars($xml);
11
+
12
+ foreach ($data['city'] as $url) {
13
+ $results_available = ceil($data2['results_available']/50);
14
+
10
- for($i = 0; $i < $results; $i++){
15
+ for($i = 0; $i < $results_available; $i++){
16
+ if($i = 0){
17
+ $detail = "http://hoge.jp/room/?key=QYGFU8OP&city_cd=" . $url->code;
18
+ } else {
11
- $results_count = $i*50;
19
+ $results_i = ($i*50)+1;
20
+ $results_count = "&start=" . $results_i . "&count=50";
21
+ $detail = "http://hoge.jp/room/?key=000&city_cd=" . $url->code . $results_count;
12
- }
22
+ }
23
+ }
24
+
25
+ $xml2 = simplexml_load_file($detail);
26
+ $data2 = get_object_vars($xml2);
13
27
  ```