2017-04-10 60 views
1
<Product> 
    <Price> 
    <SalePrice> 
     14,95 
    </SalePrice> 
    </Price> 
</Product> 
<Product> 
    <Price> 
    <SalePrice> 
    16,95 
    </SalePrice> 
    </Price> 
</Product> 



$response->xpath('Product/Price/[SalePrice <= "16,95"]/parent::* 

你好,我想要得到的每一個銷售價格等於或低於16,95,因爲它是在我的例子。但每次我嘗試,它都會給出一個空數組。如果我只使用:PHP XML Xpath得到的價格低於不工作

$response->xpath('Product/Price/[SalePrice = "16,95"]/parent::* 

我得到了一個結果。我希望你能幫助我解決這個問題。由於

+0

錯誤500是您的代碼中存在錯誤的標誌,您是否嘗試用'error_reporting(E_ALL);'來捕獲錯誤? – Jer

+1

轉義單引號或使用雙引號進行封裝。 – chris85

+0

如果你看到一個500錯誤和一個黑屏,你需要[學習如何顯示錯誤或訪問你的錯誤日誌](http://stackoverflow.com/questions/12769982/reference-what-does-this-誤差均在-PHP/12772851#12772851)。然後,如果您仍然不明白錯誤消息,請編輯您的問題以包含確切的措辭/。 – IMSoP

回答

1
  1. 翻譯逗號指向得到正確的浮點數
  2. 字符串轉換爲編號
  3. 比較浮點數,但不串

    //產品/價格/ SalePrice [數結果(翻譯(。, '', ''))< = 16.95] /父:: *

demo on eval