無趣味な人

生まれてこの方、無趣味。ハマったものこれといって特になし。

simple_html_dom 子要素を削除したplaintext

<a href="http://yahoo.co.jp/”> 文章<span class="CpName”> です</span>

というHtmlから「文章です」だけを取り出したい。 inntertextだと<span class=“CpName”>も取り出してしまう。

以下は$articleが上のhtml全体だとして、$itemに文章を取り出す方法。

$article->find('.CpName', 0)->outertext = '';
$item = trim($article->find('a', 0)->innertext); 

最初に<span class=“CpName”>を消しちゃってから、文章を取り出している。 一応trimもしている。