Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding php variable into Xpath

Tags:

php

xpath

i just need to add in a variable into the xpath my code is as followed

$target = $xml->xpath('//gig[@id=$1]');

but I need it too but something like

$target = $xml->xpath("//gig[@id=$" $change . "]");

Is this possible ?

If so could some one help ?

like image 405
Oliver Bayes-Shelton Avatar asked Jul 09 '26 05:07

Oliver Bayes-Shelton


1 Answers

Use:

$target = $xml->xpath("//gig[@id=$". $change . "]");

or, if you do not need the $ sign

$target = $xml->xpath("//gig[@id=". $change . "]");

If you need to escape a character like " in php use

\"
like image 50
Adnan Avatar answered Jul 11 '26 17:07

Adnan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!