2015-06-23 56 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";