2015-06-23 99 views
-5

爲什麼不是代碼適用?PHP strpos無法正常工作

output = {"Response":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\"><soap:Body><LeadEntryResponse xmlns=\"http:\/\/www.abc.com\/\"><LeadEntryResult><AFFILIATES_LEAD xmlns=\"\"><STATUS><LEAD_STATUS>REJECTED<\/LEAD_STATUS><REMARK> LEAD ALREADY EXSITS - <\/REMARK><\/STATUS><\/AFFILIATES_LEAD><\/LeadEntryResult><\/LeadEntryResponse><\/soap:Body><\/soap:Envelope>"} 
    key = LEAD ALREADY EXSITS 
    //CODE 
    if (strpos($output,$key) !== false) 
    { 

         echo "success"; 
     } 

輸出和密鑰來自數據庫表。

+0

[DEMO](http://ideone.com/cFlURB)示出它的工作 –

+4

堆棧溢出驅動發展 – m4t1t0

回答

0

有沒有事,爲什麼這不工作了幾個號碼,失蹤了$,缺少報價和分號,和JSON正確地訪問:

<?php 
$output = '[{"Response":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\"><soap:Body><LeadEntryResponse xmlns=\"http:\/\/www.abc.com\/\"><LeadEntryResult><AFFILIATES_LEAD xmlns=\"\"><STATUS><LEAD_STATUS>REJECTED<\/LEAD_STATUS><REMARK> LEAD ALREADY EXSITS - <\/REMARK><\/STATUS><\/AFFILIATES_LEAD><\/LeadEntryResult><\/LeadEntryResponse><\/soap:Body><\/soap:Envelope>"}]'; 
$output = json_decode($output); 
$key = "LEAD ALREADY EXSITS"; 
//CODE 
if (strpos($output[0]->Response,$key) !== false) { 
    echo "success"; 
} 
3

它不工作的第一個原因是變量應該有一個$前綴。

其次,

key = LEAD ALREADY EXSITS 

應該

$key = "LEAD ALREADY EXSITS";