ここにいくつかのコード、div[class=title]
および最も近い<p>
コンテンツを取得する方法がありますか?div[class=title]
私はforeachを取得する方法しか知りませんが、を取得する方法がわかりませんp
。ありがとう。
<?php
header("Content-type: text/html; charset=utf-8");
require_once("simple_html_dom.php");
?>
<?php
$str = <<<ETO
<div id="content">
<div class="title"><p>text1</p></div>
<p>destriction1</p>
<p>destriction2</p>
<div class="title"><p>text2</p></div>
<p>destriction3</p>
<p>destriction4</p>
<p>destriction5</p>
<div class="title"><p>text3</p></div>
<p>destriction6</p>
<p>destriction7</p>
</div>
ETO;
$html = str_get_html($str);
foreach($html->find("div[class=title]") as $content){
echo $content.'<hr />';
}
?>
次のような出力が必要です。
text1
destriction1
destriction2
------------------------------
text2
destriction3
destriction4
destriction5
------------------------------
text3
destriction6
destriction7
------------------------------