我只需要在 xpath 中添加一个变量我的代码如下
$target = $xml->xpath('//gig[@id=$1]');
但我也需要它,但是像
$target = $xml->xpath("//gig[@id=$" $change . "]");
这可能吗?
如果可以,有人可以帮忙吗?
最佳答案
使用:
$target = $xml->xpath("//gig[@id=$". $change . "]");
或者,如果您不需要 $ 符号
$target = $xml->xpath("//gig[@id=". $change . "]");
如果你需要在 php 中转义像 "这样的字符
\"
关于php - 将 php 变量添加到 Xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2109161/