php捕获后值
我无法输出名称,因为它是空的php捕获后值,php,post,Php,Post,我无法输出名称,因为它是空的 curl -d "id=1&name&age=12" http://localhost/post.php 如何得到结果为 Array ( [id] => 1 [age] => 12 ) 应该这样做试试这个: curl -d "id=1&name=&age=12" http://localhost/post.php 您可以使用 echo file_get_contents("php://input");
curl -d "id=1&name&age=12" http://localhost/post.php
如何得到结果为
Array
(
[id] => 1
[age] => 12
)
应该这样做试试这个:
curl -d "id=1&name=&age=12" http://localhost/post.php
您可以使用
echo file_get_contents("php://input");
对于名称,您必须自己解析它
parse_str(file_get_contents("php://input"), $_POST);
如果名称、id和年龄是固定参数,则可以使用默认数组并执行
array\u merge()
如下操作:
$a = explode('$', file_get_contents("php://input"));
有时用户会发布id=1&name&age=12可能用户会curl-d“id=1&name=&age=12&tt=2&uu=88&hh=&bb=”
$a = explode('$', file_get_contents("php://input"));
<?php
$default = array('id' => '', 'name' => '', 'age' => '');
$variables = array_merge($default, $_POST);
$var = 'id=1&name&age=12' ;
$text = explode('&',$var);
$text = array_flip($text);
if(!isset($text['name=']))
{
$var = str_replace('name','name=',$var);
}
echo $var ;
/* Should Return 'id=1&name=&age=12' always