Dom_Document_Helper
in package
This class should guarantee that our work with the DOMDocument is unified and safe.
Table of Contents
- $dom : DOMDocument
- Instance of the DOMDocument.
- __construct() : mixed
- Constructor.
- find_element() : DOMElement|null
- Searches for the first appearance of the given tag name.
- get_attribute_value() : string
- Returns the value of the given attribute from the given element.
- get_attribute_value_by_tag_name() : string|null
- Searches for the first appearance of the given tag name and returns the value of specified attribute.
- get_element_inner_html() : string
- Returns the inner HTML of the given element.
- get_outer_html() : string
- Returns the outer HTML of the given element.
- load_html() : void
- Loads the given HTML content into the DOMDocument.
Properties
$dom
Instance of the DOMDocument.
private
DOMDocument
$dom
Methods
__construct()
Constructor.
public
__construct(string $html_content) : mixed
Parameters
- $html_content : string
-
The HTML content to load.
Return values
mixed —find_element()
Searches for the first appearance of the given tag name.
public
find_element(string $tag_name) : DOMElement|null
Parameters
- $tag_name : string
-
The tag name to search for.
Return values
DOMElement|null —get_attribute_value()
Returns the value of the given attribute from the given element.
public
get_attribute_value(DOMElement $element, string $attribute) : string
Parameters
- $element : DOMElement
-
The element to get the attribute value from.
- $attribute : string
-
The attribute to get the value from.
Return values
string —get_attribute_value_by_tag_name()
Searches for the first appearance of the given tag name and returns the value of specified attribute.
public
get_attribute_value_by_tag_name(string $tag_name, string $attribute) : string|null
Parameters
- $tag_name : string
-
The tag name to search for.
- $attribute : string
-
The attribute to get the value from.
Return values
string|null —get_element_inner_html()
Returns the inner HTML of the given element.
public
get_element_inner_html(DOMElement $element) : string
Parameters
- $element : DOMElement
-
The element to get the inner HTML from.
Return values
string —get_outer_html()
Returns the outer HTML of the given element.
public
get_outer_html(DOMElement $element) : string
Parameters
- $element : DOMElement
-
The element to get the outer HTML from.
Return values
string —load_html()
Loads the given HTML content into the DOMDocument.
private
load_html(string $html_content) : void
Parameters
- $html_content : string
-
The HTML content to load.