PHPHtmlParser\Dom\Tag::getAttribute PHP Method

getAttribute() public method

Returns an attribute by the key
public getAttribute ( string $key ) : mixed
$key string
return mixed
    public function getAttribute($key)
    {
        if (!isset($this->attr[$key])) {
            return null;
        }
        $value = $this->attr[$key]['value'];
        if (is_string($value) && !is_null($this->encode)) {
            // convert charset
            $this->attr[$key]['value'] = $this->encode->convert($value);
        }
        return $this->attr[$key];
    }

Usage Example

Example #1
0
 public function testSetAttributes()
 {
     $attr = ['href' => ['value' => 'http://google.com', 'doublequote' => false]];
     $tag = new Tag('a');
     $tag->setAttributes($attr);
     $this->assertEquals('http://google.com', $tag->getAttribute('href')['value']);
 }
All Usage Examples Of PHPHtmlParser\Dom\Tag::getAttribute