Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

xpath search query

Featured Replies

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?

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]");

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.