Skip to content

Commit

Permalink
Merge 15fc6c0 into a4eae37
Browse files Browse the repository at this point in the history
  • Loading branch information
lussoluca committed Mar 16, 2016
2 parents a4eae37 + 15fc6c0 commit d3c22ab
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/PHPHtmlParser/Dom/AbstractNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,34 @@ public function setAttribute($key, $value)
return $this;
}

/**
* A wrapper method that simply calls the removeAttribute method
* on the tag of this node.
*
* @param string $key
* @return $this
*/
public function removeAttribute($key)
{
$this->tag->removeAttribute($key);

return $this;
}

/**
* A wrapper method that simply calls the removeAttributes method
* on the tag of this node.
*
* @param array $keys
* @return $this
*/
public function removeAttributes($keys)
{
$this->tag->removeAttributes($keys);

return $this;
}

/**
* Function to locate a specific ancestor tag in the path to the root.
*
Expand Down
33 changes: 33 additions & 0 deletions src/PHPHtmlParser/Dom/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ public function getAttribute($key)
return $this->attr[$key];
}

/**
* Removes an attribute for this tag
*
* @param string $key
* @return mixed
*/
public function removeAttribute($key)
{
$key = strtolower($key);
unset($this->attr[$key]);

return $this;
}

/**
* Removes all attributes for this tag except the ones in the $keys array
*
* @param array $keys
* @return mixed
*/
public function removeAttributes($keys)
{
$attributes = $this->getAttributes();
foreach($attributes as $key => $attribute) {
$key = strtolower($key);
if(!in_array($key, $keys)) {
unset($this->attr[$key]);
}
}

return $this;
}

/**
* Generates the opening tag for this object.
*
Expand Down

0 comments on commit d3c22ab

Please sign in to comment.