嘿伙计们,所以我将字段发布到网址, 使用print $ result返回的数据显示如下(来自浏览器中的视图源)
<html>
<body>TransID=0&REFNO=&Auth=&AVSCode=&CVV2ResponseMsg=&Notes=Your merchant information is not correct.&User1=&User2=&User3=&User4=
</body>
</html>
上方还有1个空行 现在我需要把那些身体对作为一个数组,这样我就可以和他们一起工作了......我对正则表达式或类似的东西不太好,以获得它们......请帮忙
答案 0 :(得分: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] =>
)
*/
答案 1 :(得分: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);