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?
为文本区域设置dom元素的textContent无效,但是将其设置为nodeValue则同时设置了nodeValue和textContent。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.