Php 解析curl响应数据

Php 解析curl响应数据,php,curl,preg-match,Php,Curl,Preg Match,嘿,伙计们,我把字段发布到一个url上, 使用print$结果返回的数据如下所示(来自浏览器中的view source) TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=您的商户信息不正确。&User1=&User2=&User3=&User4= 屏幕上方还有一个空行 现在我需要把这些体对作为一个数组,这样我就可以使用它们了。我不擅长使用正则表达式或类似的东西来获取它们。请帮助我。你可以通过标准php函数来解决这个问题 <?

嘿,伙计们,我把字段发布到一个url上, 使用print$结果返回的数据如下所示(来自浏览器中的view source)


TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=您的商户信息不正确。&User1=&User2=&User3=&User4=
屏幕上方还有一个空行
现在我需要把这些体对作为一个数组,这样我就可以使用它们了。我不擅长使用正则表达式或类似的东西来获取它们。请帮助我。你可以通过标准php函数来解决这个问题

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

)

*/
 $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);
$cContent=”
TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=您的商户信息不正确。&User1=&User2=&User3=&User4=
";
echo$cContent=修剪(带标签($cContent));
parse_str($cContent,$aParams);
印刷费($aParams);

你想解析html还是只解析body标记之间的字符串?我只需要TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=你的商户信息不正确。&User1=&User2=&User3=&User4=如果我把它作为一个数组,那么我就可以像$response['TransID']$response['REFNO']一样处理它了。。。etc
TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=您的商户信息不正确。&User1=&User2=&User3=&User4=
您将其放在一个变量中,还是将其与html和内体标记一起?这是页面的视图源
 $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);