PHPHtmlParser\Dom\Tag::setAttribute PHP Method

setAttribute() public method

Set an attribute for this tag.
public setAttribute ( string $key, string | array $value )
$key string
$value string | array
    public function setAttribute($key, $value)
    {
        $key = strtolower($key);
        if (!is_array($value)) {
            $value = ['value' => $value, 'doubleQuote' => true];
        }
        $this->attr[$key] = $value;
        return $this;
    }

Usage Example

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