2

This might just be a problem with the php syntax, but why does this work:

$b = new DOMXPath($z);
$b = $x->query('//div[contains(@class,"xxx")]');

but using double quotes with single inside does not:

$b = $x->query("//div[contains(@class,'xxx')]//a");
nickb
  • 59,313
  • 13
  • 108
  • 143
John Smith
  • 111
  • 5
  • 1
    Are you sure? Actually both on the Xpath as on the PHP side this should not make a difference. Probaly the added `//a` makes the difference here? See as well [Encoding XPath Expressions with both single and double quotes](http://stackoverflow.com/q/642125/367456). – hakre Jun 22 '12 at 00:43
  • no that was added by mistake in the question. without the a it doesn't work – John Smith Jun 22 '12 at 00:45
  • Most xpath examples are with single quotes, which would be your variant that does *not* work. Please really double-check you don't have some other issue here. It's highly likely. Welcome to Stack Overflow by the way. – hakre Jun 22 '12 at 00:46
  • 1
    Can you provide a minimum example of HTML and PHP code that demonstrates how this does not work? – nickb Jun 22 '12 at 00:47

1 Answers1

0

Maybe it has something to do with the single quote inside the string.

Try this:

$b = $x->query("//div[contains(@class,\"xxx\")]//a");

Otherwise I would just stick to the single quote version. Whats the big deal anyway?

Vincent
  • 2,342
  • 1
  • 17
  • 22