Home >Backend Development >PHP Tutorial >php 正则提取XML 指定内容方法?求大拿帮忙(史上最难)

php 正则提取XML 指定内容方法?求大拿帮忙(史上最难)

WBOY
WBOYOriginal
2016-06-23 14:27:45826browse

有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 提取出AAAAAAA 和 DGM20131121000009 中的 “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);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn