I am using PHP DOMDocument class to parse the HTML file, and using the code,
$dom =new DOMDocument();
@$dom->loadHTMLFile($file_path);
$dom->getElementById("my_id")
to fetch the data of the element with the ID "my_id", but the problem is the HTML document is containing multiple elements with same ID, and i want the data in all that elements.. The HTML code,
<div id="my_id">
phone number 123
</div>
<div id="my_id">
address somewhere
</div>
<div id="my_id">
date of birth
</div>
i know the ID is unique, but here the case is like that.. in this case will getElementById() will return an array..
No, if anything
getElementById()will return aDOMElement. In case of multiple returned nodes, results would be aDOMNodeList, but that doesnt apply here.Furthermore, DOM will not recognize your IDs until you validate the Document against a DTD or Schema file that defines the id attribute as an actual XML ID attribute, which is different from other attributes. That's why
DOMAttrhas a methodisIdand XML requires IDs to be of unique value. As VolkerK pointed out in the comments, when usingloadHTMLFile, this validation will occur automatically.See my answer to Simplify PHP DOM XML parsing - how? for more detailed information.