日期:2014-05-16  浏览次数:20427 次

php 正则提取XML 指定内容方法?求大拿帮忙(史上最难)
有XML内容 
<?xml version="1.0" encoding="GBK"?>
<stream><MSGCODE>AAAAAAA</MSGCODE><MSGCN>交易成功!</MSGCN><B2CCERTNO>500415</B2CCERTNO><ORDERDATE>2013-11-21</ORDERDATE><ORDERTIME>09:52:23</ORDERTIME><ORDERNO>DGM20131121000009</ORDERNO><ORDERAMT>6.26</ORDERAMT><CURRID>01</CURRID><PAYAMT>6.26</PAYAMT><PAYNO>BC131121095428004271</PAYNO><ACCNO>6226********6770</ACCNO><ACCTYPE>01</ACCTYPE><PBCSTNAME>测试</PBCSTNAME><ACCHASH>fSSczJM0fims1Xpmrvi2pnBtrr4=</ACCHASH></stream>



求使用PHP 提取出<MSGCODE>AAAAAAA</MSGCODE> 和 <ORDERNO>DGM20131121000009</ORDERNO> 中的 “AAAAAA"和 ”DGM20131121000009“ 可以使用正则进行匹配

------解决方案--------------------
$string = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<stream><MSGCODE>AAAAAAA</MSGCODE><MSGCN>交易成功!</MSGCN><B2CCERTNO>500415</B2CCERTNO><ORDERDATE>2013-11-21</ORDERDATE><ORDERTIME>09:52:23</ORDERTIME><ORDERNO>DGM20131121000009</ORDERNO><ORDERAMT>6.26</ORDERAMT><CURRID>01</CURRID><PAYAMT>6.26</PAYAMT><PAYNO>BC131121095428004271</PAYNO><ACCNO>6226********6770</ACCNO><ACCTYPE>01</ACCTYPE><PBCSTNAME>测试</PBCSTNAME><ACCHASH>fSSczJM0fims1Xpmrvi2pnBtrr4=</ACCHASH></stream>
XML;

preg_match_all('#<(MSGCODE
------解决方案--------------------
ORDERNO)>(.+)</\1#s',$string,$m);
print_r($m);