-1

文字列 (DB に格納されている) からコンテンツを抽出するのに苦労しています。各 div は章であり、h2 コンテンツはタイトルです。各チャプター(div)のタイトルと内容を分けて抽出したい

<p>
<div>
   <h2>Title 1</h2>
   Chapter Content 1 with standard html tags (ex: the following tags)
   <strong>aaaaaaaa</strong><br />
   <em>aaaaaaaaa</em><br />
   <u>aaaaaaaa</u><br />
   <span style="color:#00ffff"></span><br />
</div>
<div>
   <h2>Title 2</h2>
   Chapter Content 2
</div>
...
</p>

PHPでpreg_match_allを試してみましたが、標準のhtmlタグがあると機能しません

function splitDescription($pDescr)
{
    $regex = "#<div.*?><h2.*?>(.*?)</h2>(.*?)</div>#";
    preg_match_all($regex, $pDescr, $result);

    return $result;
}
4

2 に答える 2