0

嘿伙计们,所以我将字段发布到 url,使用 print $result 返回的数据显示如下(来自浏览器中的查看源代码)

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

上面还有 1 个空行现在我需要将这些身体对作为一个数组获取,以便我可以使用它们..我不擅长使用正则表达式或类似的东西来获取它们..请帮助

4

2 回答 2

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] => 

)

*/
于 2012-11-23T17:46:52.417 回答
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);
于 2012-11-23T18:00:01.733 回答