public function QueryPath::attr in QueryPath 7.2
Same name and namespace in other branches
- 6 QueryPath/QueryPath.php \QueryPath::attr()
- 7.3 QueryPath/QueryPath.php \QueryPath::attr()
3 calls to QueryPath::attr()
- QueryPath::css in QueryPath/
QueryPath.php - QueryPath::dataURL in QueryPath/
QueryPath.php - QueryPath::val in QueryPath/
QueryPath.php
File
- QueryPath/
QueryPath.php, line 319
Class
Code
public function attr($name = NULL, $value = NULL) {
if (is_null($name)) {
if ($this->matches
->count() == 0) {
return NULL;
}
$ele = $this
->getFirstMatch();
$buffer = array();
foreach ($ele->attributes as $name => $attrNode) {
$buffer[$name] = $attrNode->value;
}
return $buffer;
}
if (is_array($name)) {
foreach ($name as $k => $v) {
foreach ($this->matches as $m) {
$m
->setAttribute($k, $v);
}
}
return $this;
}
if (isset($value)) {
foreach ($this->matches as $m) {
$m
->setAttribute($name, $value);
}
return $this;
}
if ($this->matches
->count() == 0) {
return NULL;
}
if ($name == 'nodeType') {
return $this
->getFirstMatch()->nodeType;
}
return $this
->getFirstMatch()
->getAttribute($name);
}