0

I would like to change the 4c050652f0c3e ( of <testimonial id="xxx"> ) to a dynamic variable that it is sent through a form. My variable is $nodeid = $_POST['nodeid']; but i can not replace it right.

This is the code

foreach( $testimonials->xpath("testimonial[@id='4c050652f0c3e']") as $t ) {
  $t->$_POST['tagname'] = $_POST['newname'];
}

This is what I did but it is not right

foreach( $testimonials->xpath("testimonial[@id=$_POST['nodeid']]") as $t ) {
  $t->$_POST['tagname'] = $_POST['newname'];
}

Thank you!

2
  • shouldnt a xpath exp. start with "//"? Commented Jan 5, 2011 at 14:55
  • @MrQ.C. no, that's just telling the XPath expression to match anywhere in the document, which is not necessarily what's wanted. Commented Jan 5, 2011 at 15:01

3 Answers 3

1

foreach works on a copy of your array, so this would not work. You could use a different loop (for loop?), or use references to the array

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

Comments

1

Try this:

foreach( $testimonials->xpath("testimonial[@id='".$_POST['nodeid']."']") as $t ) {
  $t->$_POST['tagname'] = $_POST['newname'];
}

Comments

0

try add '

foreach( $testimonials->xpath("testimonial[@id='".$_POST['nodeid']]."'") as $t ) {
  $t->$_POST['tagname'] = $_POST['newname'];
}

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.