getElementsByTagName() public method

public getElementsByTagName ( $name, $idx )
示例#1
0
 /**
  * Search a DOM for a selector and return the contents.
  *
  * @param simple_html_dom $dom The DOM to search.
  * @param string $selector The CSS style selector for the content to find.
  * @param string $default The default content to return if the node isn't found.
  * @return string Returns the content of the found node or {@link $default} otherwise.
  */
 function domGetContent($dom, $selector, $default = '')
 {
     $Element = $dom->getElementsByTagName($selector);
     return isset($Element->content) ? $Element->content : $default;
 }
示例#2
0
HTML;
$html->load($str);
assert($html == $str);
assert($html->plaintext == 'okok</div>');
// -----------------------------------------------------------------------------
// old fashion camel naming conventions test
$str = <<<HTML

<input type="checkbox" id="checkbox" name="checkbox" value="checkbox" checked>
<input type="checkbox" id="checkbox1" name="checkbox1" value="checkbox1">
<input type="checkbox" id="checkbox2" name="checkbox2" value="checkbox2" checked>
HTML;
$html->load($str);
assert($html == $str);
assert($html->getElementByTagName('input')->hasAttribute('checked') == true);
assert($html->getElementsByTagName('input', 1)->hasAttribute('checked') == false);
assert($html->getElementsByTagName('input', 1)->hasAttribute('not_exist') == false);
assert($html->find('input', 0)->value == $html->getElementByTagName('input')->getAttribute('value'));
assert($html->find('input', 1)->value == $html->getElementsByTagName('input', 1)->getAttribute('value'));
assert($html->find('#checkbox1', 0)->value == $html->getElementById('checkbox1')->getAttribute('value'));
assert($html->find('#checkbox2', 0)->value == $html->getElementsById('checkbox2', 0)->getAttribute('value'));
$e = $html->find('[name=checkbox]', 0);
assert($e->getAttribute('value') == 'checkbox');
assert($e->getAttribute('checked') == true);
assert($e->getAttribute('not_exist') == '');
$e->setAttribute('value', 'okok');
assert($e == '<input type="checkbox" id="checkbox" name="checkbox" value="okok" checked>');
$e->setAttribute('checked', false);
assert($e == '<input type="checkbox" id="checkbox" name="checkbox" value="okok">');
$e->setAttribute('checked', true);
assert($e == '<input type="checkbox" id="checkbox" name="checkbox" value="okok" checked>');