0

<p> and <ul>/<ol>HTMLの分析とタグの検索に関する私の他の質問に加えて、この質問。

$in = '<p>Bit\'s of text</p><p>another paragraph</p><ol><li>item1</li><li>item2</li></ol><p>paragraph</p>';

function geefParagrafen($in){
  $dom = new domDocument;
  $dom->loadHTML($in);
  $x = $dom->documentElement;
}

これが私が得た距離です。以下を含む配列として $out を取得する方法は何ですか:

$out = array('<p>Bit's of text</p><p>another paragraph</p>',
'<p>another paragraph</p>',
'<ol><li>item1</li><li>item2</li></ol>',
'<p>paragraph</p>');

前もって感謝します!私はdomdocument構造で本当に迷っています。

4

1 に答える 1

2
$in = '<p>Bit\'s of text</p><p>another paragraph</p><ol><li>item1</li><li>item2</li></ol><p>paragraph</p>';


$dom = new domDocument;
$dom->loadHTML($in);

$children = $dom->getElementsByTagName('body')->item(0)->childNodes;

$out = array();

foreach ($children as $child) {
    $out[] = $dom->saveXML($child);
}

print_r($out);
于 2009-09-21T11:31:26.080 に答える