I've got an element by name attribute in Php using a DOMDocument (I do not want to use id) but how can I then set it's textContent and save to the dom object?
So far I have the following code:
$dom = new DOMDocument();
$dom->loadHTML($html);
foreach($dom->getElementsByTagName('*') as $element ){
$element_name = $element->getAttribute("name");
if($element_name == 'mytextareaname') {
$element->textContent = "Some text content";
}
}
$html_with_values = $dom->saveHTML();
But the values are not saved, because I probably need to reference the $dom object when saving rather than $element. How can I do that, can I add a key to the foreach and use that?
Setting the dom element's textContent for a textarea did not work, but setting it's nodeValue set both nodeValue and textContent.