1

を使用した次の PHP コードがあるとしますDOMDocument

$inputs = $xpath->query('//input | //select | //textarea', $form);

if ($inputs->length > 0)
{
    for ($j = 0; $j < $inputs->length; $j++)
    {
        $input = $inputs->item($j);

        $input->getAttribute('name'); // Returns the Attribute
        $input->getTag(); // How can I get the input, select or textarea tag?
    }
}

一致した各ノードのタグ名を知るにはどうすればよいですか?

4

1 に答える 1

3
$inputs = $xpath->query('//input | //select | //textarea', $form);

// no need for "if ($inputs->length > 0) - the for loop won't run if it is 0
for ($j = 0; $j < $inputs->length; $j++)
{
  $input = $inputs->item($j);
  echo $input->nodeName;
}

参照: http://www.php.net/manual/en/class.domnode.php#domnode.props.nodename

PS: ドキュメントを調べる以外に、 avar_dump()は非常に役立ちます。

于 2009-08-17T16:28:50.560 に答える