在DOMXpath查询中使用双引号而不是单引号将失败

时间:2021-04-29 22:26:55

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

这可能只是php语法的问题,但是为什么这样做呢:

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

1 个解决方案

#1


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?

否则,我就只使用单引用版本。有什么大不了的?

#1


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?

否则,我就只使用单引用版本。有什么大不了的?