0

I cant seem to get this query right. What I'm trying to achieve is:

Update the value inside my text node.

But the problem is that instead of updating the value it keeps adding the value to the element.

Say I $_POST 'Hello' to the value. It adds value. But later I want to change the value 'Hello' to 'God Bye' instead of modify the node to 'Hello God Bye'.

I have tried I'm using PHP DOM. But can't seem to get it with SimpleXML either.

Any suggestions ?

This is what I have for now:

$xml = new DOMDocument();
$xml->formatOutput = TRUE;
$xml->preserveWhiteSpace = FALSE; 
$xml->load('../stickers.xml');

$xpath = new DOMXPath($xml);

$result = $xpath->query('/stickers/sticker[id="559428"]/text');
$result->item(0)->nodeValue .= 'Hello';

echo $xml->saveXML();
$xml->save('../stickers.xml');

2 Answers 2

1

Try changing

$result->item(0)->nodeValue .= 'Hello';

into

$result->item(0)->nodeValue = 'Hello';

The dot there is concatenating the strings.

Sign up to request clarification or add additional context in comments.

1 Comment

OMG!! I have been struggling for DAYS with this.. Thank you so much!! I love u!
1

You're using .= which is meant for adding onto strings. Replace it with =.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.