美好的一天!
我使用file_get_contents从远程地址给出答案,并为create array提供数据爆炸。
为此,我使用下一个代码:
function test(){
$project_key='fg54gth5k7';
$postdata = http_build_query(
array(
'code' => $project_key
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://test.com/', false, $context);
return $result;
}
$res = test();
echo $res;
$part=explode(' ',$res);
var_dump($part);
echo $ res返回行:
3434343 http://test.com/index.php?r=site/stepone
&temptoken=c68c0ae1cece433fe5d6f6578cc0a9b6 OK68 OK Redirect
http://test.com/index.php?r=site/stepone&temptoken=c68c0ae1cece433fe5d6f6578cc0a9b6 0
var_dump()返回数组
array(5) {
[0]=> string(8) "3434343"
[1]=> string(0) ""
[2]=> string(0) ""
[3]=> string(110) "http://test.com/index.php?r=site/stepone
&temptoken=c68c0ae1cece433fe5d6f6578cc0a9b6 OK68 OK Redirect"
[4]=> string(100) "http://test.com/index.php?
r=site/stepone&temptoken=c68c0ae1cece433fe5d6f6578cc0a9b6 0 "
}
请告诉我,为什么我的数组错误?
数组应该是下一个:
array(10) {
[0]=> string(8) "3434343"
[1]=> string(0) ""
[2]=> string(0) ""
[3]=> string(110) "http://test.com/index.php?r=site/stepone
&temptoken=c68c0ae1cece433fe5d6f6578cc0a9b6"
[4]=> string(4) "OK68 OK Redirect"
[5]=> string(2) "OK Redirect"
[6]=> string(8) "Redirect"
[7]=> string(100) "http://test.com/index.php?
r=site/stepone&temptoken=c68c0ae1cece433fe5d6f6578cc0a9b6"
[8]=> string(1) "0"
[9]=> string(0) ""
请告诉我哪里有错误?
答案 0 :(得分:3)