【发布时间】:2013-10-13 07:06:00
【问题描述】:
它只能检测第一个条件,if else 的任何东西都行不通。 xpath 是正确的。如果我在没有循环的情况下这样做,它将起作用。我在这里做错了什么吗?
$pricediscount = "";
$chinesename ="";
if (empty($pricediscount)){
$pricediscount = (@$xpath->query("//*[@id='J_PromoPrice']/div/strong/text()")->item(0)->nodeValue);
}elseif(empty($pricediscount)){
$pricediscount = (@$xpath->query("//*[@id='J_StrPrice']/em[2]")->item(0)->nodeValue);
}elseif(empty($pricediscount)){
$pricediscount = (@$xpath->query("//*[@id='J_PromoBox']/strong")->item(0)->nodeValue);
}elseif(empty($pricediscount)){
$pricediscount = (@$xpath->query("//*[@id='J_StrPrice']")->item(0)->nodeValue);
}else{
$pricediscount = "NA";
}
【问题讨论】:
-
嗯,你正在测试相同的条件 3 次......你到底想做什么?
-
如果第一个else if为空,则继续下一个else if
-
如果第一个是空的,所有其他的也是空的,你一遍又一遍地测试同样的东西......我不明白你的逻辑是什么。
-
如果第一个 xpath 查询不起作用,请尝试下一步。如果它有一些东西,它会用一些东西更新 $priceiscount。所以如果有东西不是空的,那就停下来
-
"//*[@id='J_StrPrice']" *************** 两者不同 *********** * @$xpath->query("//*[@id='J_PromoBox']/strong"