2012-11-23 79 views
0

嗨所以我真的張貼字段爲一個URL, 通過使用打印$結果返回的數據示出了這樣的(從在瀏覽器中查看源)解析捲曲響應數據

<html> 
     <body>TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=Your merchant information is not correct.&User1=&User2=&User3=&User4= 
     </body> 
    </html> 

有1更多的空行上述 現在我需要讓那些身體對一個數組,所以我可以用them..i`m無法與正則表達式或類似的東西很好的工作就是讓them..pls幫助

+0

你想解析html或只是身體標記之間的字符串? – GBD

+0

我只需要的東西 TRANSID = 0&引用號=驗證= AVSCode = CVV2ResponseMsg =注=您的商戶信息是不正確的。與用戶1 =用戶2 =用戶3 =用戶4 = 將是巨大的,如果我把它作爲一個數組所以我可以像 $ response ['TransID'] $ response ['REFNO'] ... etc – misulicus

+0

'TransID = 0&REFNO =&Auth =&AVSCode =&CVV2ResponseMsg =&Notes =您的商家信息不正確。&User1 =&User2 =&User3 =&User4 ='這你有一個變量或它與HTML和體內標籤? – GBD

回答

1
<?php 

$html = "<html> 
     <body>TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=Your merchant information is not correct.&User1=&User2=&User3=&User4= 
     </body> 
    </html>"; 

$dom = new DOMDocument(); 
@$dom->loadHTML($html); //Lots of invalid html going on so I am suppressing the warnings 
$xpath = new DOMXPath($dom); 

$str = $xpath->query('//body/text()')->item(0)->textContent; 

parse_str($str, $params); 

print_r($params); 

/* 

Array 
(
    [TransID] => 0 
    [REFNO] => 
    [Auth] => 
    [AVSCode] => 
    [CVV2ResponseMsg] => 
    [Notes] => Your merchant information is not correct. 
    [User1] => 
    [User2] => 
    [User3] => 
    [User4] => 

) 

*/ 
0

你可以通過標準的php函數來解決這個問題

$cContent = "<html> 
    <body>TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=Your merchant information is not correct.&User1=&User2=&User3=&User4= 
    </body> 
</html>"; 

echo $cContent = trim(strip_tags($cContent)); 


parse_str($cContent, $aParams); 

print_r($aParams);