Reputation: 147
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
Reputation: 125664
try add '
foreach( $testimonials->xpath("testimonial[@id='".$_POST['nodeid']]."'") as $t ) {
$t->$_POST['tagname'] = $_POST['newname'];
}
Upvotes: 0
Reputation: 3091
Try this:
foreach( $testimonials->xpath("testimonial[@id='".$_POST['nodeid']."']") as $t ) {
$t->$_POST['tagname'] = $_POST['newname'];
}
Upvotes: 1
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