2010-11-18 5 views
0

私は私が働いている上で混乱しています。私は<div></div>のクローズタグを、それぞれ単純なHTMl DOMパーサーを使って開くまでエコーしようとしています。 (http://simplehtmldom.sourceforge.net/manual.htm)から与えられたこの例を使用すると、主要なdivタグの中にテキスト領域をエコーし​​ようとします。PHPの単純なDOMパーサーの混乱、ヘルプのタグをエコー:<div>content code</div>

私は <div>と、そのID、テキストまたは全くコードをその中に含むエコーしたいともコードが終わるところ、私が識別されるように終了タグ </div>をエコーし​​たらどう
// Find all <div> which attribute id=foo 
$ret = $html->find('div[id=foo]'); 

// Find all <div> with the id attribute 
$ret = $html->find('div[id]'); 

答えて

1

「HTML要素の属性へのアクセス方法」のdocumentation for simplehtmldomに示されているとおり、タブの "Magic Attributes":

// Example 
$html = str_get_html("<div>foo <b>bar</b></div>"); 
$e = $html->find("div", 0); 

echo $e->tag; // Returns: " div" 
echo $e->outertext; // Returns: " <div>foo <b>bar</b></div>" 
echo $e->innertext; // Returns: " foo <b>bar</b>" 
echo $e->plaintext; // Returns: " foo bar" 

Attribute Name Usage 
$e->tag   Read or write the tag name of element. 
$e->outertext  Read or write the outer HTML text of element. 
$e->innertext  Read or write the inner HTML text of element. 
$e->plaintext  Read or write the plain text of element. 
+0

編集済みの質問を編集して、それを明確にするために、開いた

tag, its content/s, and also the close
タグをエコーし​​たいと思います。 – woninana

+0

@Stupefy 'outertext'はどうしていませんか? – Gordon

+0

それは動作します!どうもありがとう! :D:D – woninana

関連する問題