JBEnergy
JBEnergy

Reputation: 147

PHP XML simple variable problem

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!

Upvotes: 0

Views: 143

Answers (3)

Haim Evgi
Haim Evgi

Reputation: 125664

try add '

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

Upvotes: 0

dfilkovi
dfilkovi

Reputation: 3091

Try this:

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

Upvotes: 1

Nanne
Nanne

Reputation: 64429

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

Upvotes: 1

Related Questions