各要素の属性の幅と高さを取得するにはどうすればよいですか?
例えば、
$dom = new DOMDocument;
$dom->loadHTML('<div class="item" style="width:295px; height:210px; border:1px solid #000;"></div><div></div>');
foreach( $dom->getElementsByTagName('div') as $node )
{
$style = $node->getAttribute( 'style' );
var_dump($style);
}
結果、
string 'width:295px; height:210px; border:1px solid #000;' (length=49)
string '' (length=0)
しかし、これらは私が求めているものです。
div
クラス名がitem
onlyの を選択します。295
(幅) と210
(高さ) のみを取得します。
DOMで可能ですか?またはXPATH?
編集:
クラス名でdivを選択することはできたようですが、
$dom = new DOMDocument;
$dom->loadHTML('<div class="item" style="width:295px; height:210px; border:1px solid #000;"></div><div></div>');
$xpath = new DOMXpath($dom);
foreach ($xpath->query('//*[@class="item"]') as $node) {
$style = $node->getAttribute( 'style' );
var_dump($style);
}
今、これは私が求めているものです。
295
(幅) と210
(高さ)を取得します。