※ 引述《o500521 (poet)》之銘言:
: ------------------以下是html------------------
: ...</div><h1>字串1</h1><div>...</div><div class="aff">
: <h3 class="label">Source</h3><p>字串2</p></div>
: <div class="abstr"><h3>Abstract</h3><p>字串3</p></div>
: ----------------------------------------------
: 使用preg_match_all("|<[</h1><p>]>(.*)[</p></div>]+>|U", $P_string, $P_dd) ;
: 抓到
: 字串2 字串3
: 但想要的是
: 字串1 字串3
: 研究一下 發現我還是沒辦法解決正規化表示法的問題
: 謝謝大家耐心的閱覽...
要不要用其他工具?
如果是 parsing HTML,可以用 DOMDocument:
$htmlDom = new DOCDocument();
$htmlDom->loadHTML($HtmlString);
$h1 = $htmlDom->getElementsByTagName('h1')->item(0);
$p = $htmlDom->getElementsByTagName('p')->item(0);
echo $h1->nodeValue;
echo $p->nodeValue;
==
不是很確定能不能動,憑印象與 manual 打出來的...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.242.135.97