April 27, 200818 yr hi guys, i'm tring to search through a XML doc with SIMPLEXML, but i mus have my syntax wrong $prop = $xml->xpath('/root/property[id=$id]'); foreach { $prop as &list) { //do something } i know that this works is i enter say 61245 instead of $id. what is the correct syntax to stick a variable into this query? i have tried multiple variation but i'm stumped?
April 27, 200818 yr you are using single quotes instead of double quotes, these two will work: $prop = $xml->xpath("/root/property[id=$id]"); $prop = $xml->xpath('/root/property[id='.$id.']'); For simplicity's sake, you can change your XPATH to: $prop = $xml->xpath("//property[id=$id]");
April 27, 200818 yr Author you are using single quotes instead of double quotes, these two will work: $prop = $xml->xpath("/root/property[id=$id]"); $prop = $xml->xpath('/root/property[id='.$id.']'); For simplicity's sake, you can change your XPATH to: $prop = $xml->xpath("//property[id=$id]"); cheers man, i'm sure i tried the 2nd example you gave, obviously it wasn't the same. thanks mate:)
Create an account or sign in to comment