简体   繁体   English

解析卷曲响应数据

[英]parse curl response data

Hey guys so i`m posting fields to a url, the data returned by using a print $result shows like this (from view source in the browser) 大家好,我将字段发布到url,使用打印$ result返回的数据显示如下(来自浏览器的视图源)

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

there is 1 more empty row above the now i need to get those body pairs as an array so i can work with them..i`m not good with regex or stuff like that to get them..pls help 上面还有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] => 

)

*/

You can solve this by standart php functions 您可以通过standart 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM