Here is my code:
$xpath_query = $xpath->query('//div[@class="paragraph-content"]//h2[1]');
$i = 0;
foreach($xpath_query as $header){
if (!empty($header->nodeValue) && $i == 0){
$replacement = $dom->createDocumentFragment();
$replacement ->appendXML("<h1>$header->nodeValue</h1>");
$header->parentNode->replaceChild($replacement , $header);
}
$i++;
}
I'm grabbing the <h2> tag in the xpath and replacing it with <h1>
Where there is a value like this "Dialed in to hike & trail" in the <h2> tag and its being replaced to <h1> tag it doesn't show the text.
the "&" or & is causing the replacement to break, the $header->nodeValue
how can I escape $header->nodeValue, meaning if there are cases in the string where I have a <br> tag or &. When I have a <br> tag or have & in the text, it breaks the replacement.