attr() public method

- If no parameters are specified, this returns an associative array of all name/value pairs. - If both $name and $value are set, then this will set the attribute name/value pair for all items in this object. - If $name is set, and is an array, then all attributes in the array will be set for all items in this object. - If $name is a string and is set, then the attribute value will be returned. When an attribute value is retrieved, only the attribute value of the FIRST match is returned.
See also: removeAttr()
See also: tag()
See also: hasAttr()
See also: hasClass()
public attr ( mixed $name = null, string $value = null ) : mixed
$name mixed The name of the attribute or an associative array of name/value pairs.
$value string A value (used only when setting an individual property).
return mixed If this was a setter request, return the DOMQuery object. If this was an access request (getter), return the string value.
 /**
  * Extract a single value
  *
  * @param \QueryPath\DOMQuery $item
  * @param array $mapping
  * @param string $value
  * @return string
  */
 protected function _extractValue(\QueryPath\DOMQuery $item, array $mapping, $value = '')
 {
     if ($item) {
         if (!empty($mapping['attr'])) {
             $value = $item->attr($mapping['attr']);
         } elseif (!empty($mapping['innerHTML'])) {
             $value = $item->innerHTML();
         } else {
             $value = $item->text();
         }
     }
     $value = mb_convert_encoding($value, 'UTF-8', 'auto');
     if (!empty($mapping['preg'])) {
         if (preg_match($mapping['preg'], $value, $matches)) {
             $value = isset($matches[1]) ? $matches[1] : $matches[0];
         }
     }
     if (!empty($mapping['wrap'])) {
         $value = str_replace('|', $value, $mapping['wrap']);
     }
     if (!empty($mapping['strtotime'])) {
         $value = strtotime($value);
     }
     if (!isset($mapping['trim']) || !empty($mapping['trim'])) {
         $value = trim($value);
     }
     return $value;
 }