How do I access PHP's replaceChild
method? I need to find and replace all instances of a specific element (in this example a
anchor elements). I've been at this for hours already and I can't find it any where. One server is running PHP 5.6.2 and another 5.5.0.
$row1 = '<div><p>A test!</p><a>aaa</a><p>A test!</p><a>bbb</a></div>';
$dom = new DOMDocument();
$dom->loadXML($row1);
$xpath = new DOMXPath($dom);
$entries = $xpath->query('a');
foreach ($entries as $entry)
{
echo '<div><pre>'; print_r($entry); echo '</pre></div>';//Nope
echo '<div><pre>'; print_r($entry->parentNode); echo '</pre></div>';//More Nope
}
An example of what this returns:
DOMElement Object
(
[tagName] => a
[schemaTypeInfo] =>
[nodeName] => a
[nodeValue] => aaa
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] => (object value omitted)
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => a
[baseURI] => //Private
[textContent] => aaa
)
Regardless of whether I'm accessing the element directly or indirectly print_r
never reveals PHP's replaceChild
method! Obviously I read the manual. No other questions on here have any where near a working applicable answer. Suggestions please?
Update: I've abandoned the specific approach that required this due to an utter lack of a working answer any where and this isn't a duplicate if there is no working answer (hint: there is not, drive-by-mod should be banned). For future purposes if I have not accepted an answer then I can not guarantee that it worked in any way though I will comment if I have time to start testing it. I'll leave this here for the benefit of others. As for my project I essentially used a bit of explode()
in PHP to get the job done which is lame but not as lame as php.net lacking working examples or people posting not-working-answers elsewhere.