回答編集履歴

4

修正

2016/09/20 13:12

投稿

popobot
popobot

スコア6586

test CHANGED
@@ -28,13 +28,13 @@
28
28
 
29
29
  $en_divs = $xpath->query('div[@class="en_text"]', $div); // そのdivからclassがen_textの<div>を探す
30
30
 
31
- if(!empty($en_divs[0])) {
31
+ if($en_divs->length) { // divがあったら
32
32
 
33
- $div->removeChild($en_divs[0]); // en_textのdivを消す
33
+ $div->removeChild($en_divs->item(0)); // en_textのdivを消す
34
34
 
35
35
  }
36
36
 
37
- echo $div->nodeValue ."\n"; // <div>内の値をechoで出力する
37
+ echo $div->nodeValue ."\n"; // <div>内の値をechoで出力する
38
38
 
39
39
  }
40
40
 

3

さらに修正

2016/09/20 13:12

投稿

popobot
popobot

スコア6586

test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  $en_divs = $xpath->query('div[@class="en_text"]', $div); // そのdivからclassがen_textの<div>を探す
30
30
 
31
- if($en_divs->length) { // divがあったら
31
+ if(!empty($en_divs[0])) {
32
32
 
33
33
  $div->removeChild($en_divs[0]); // en_textのdivを消す
34
34
 

2

凡ミス修正

2016/09/20 13:05

投稿

popobot
popobot

スコア6586

test CHANGED
@@ -36,6 +36,8 @@
36
36
 
37
37
  echo $div->nodeValue ."\n"; // <div>内の値をechoで出力する
38
38
 
39
+ }
40
+
39
41
  ```
40
42
 
41
43
 

1

修正

2016/09/20 13:00

投稿

popobot
popobot

スコア6586

test CHANGED
@@ -22,13 +22,19 @@
22
22
 
23
23
  $xpath = new DOMXPath($dom); // XPathオブジェクトを作る
24
24
 
25
- $divs = $xpath->query('//div[@class="en_text"]'); // classがen_textの<div>を探す
25
+ $divs = $xpath->query('//div[@class="text"]'); // classがtextの<div>を探す
26
26
 
27
27
  foreach($divs as $div) { // 見つかった<div>が配列になっているのでループで回す
28
28
 
29
- echo $div->nodeValue ."\n"; // <div>内の値echoで出力
29
+ $en_divs = $xpath->query('div[@class="en_text"]', $div); // そのdivからclassがen_textの<div>を
30
30
 
31
+ if($en_divs->length) { // divがあったら
32
+
33
+ $div->removeChild($en_divs[0]); // en_textのdivを消す
34
+
31
- }
35
+ }
36
+
37
+ echo $div->nodeValue ."\n"; // <div>内の値をechoで出力する
32
38
 
33
39
  ```
34
40