Reputation: 311
curl -d "id=1&name&age=12" http://localhost/post.php
i am having problem to output name because its empty
Array
(
[id] => 1
[age] => 12
)
how to get result as
Array
(
[id] => 1
[age] => 12
[name] =>
)
Upvotes: 1
Views: 398
Reputation: 686
$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
Upvotes: 1
Reputation: 43619
If name, id and age are fixed parameters, you can use a default array and do an array_merge()
like this:
<?php
$default = array('id' => '', 'name' => '', 'age' => '');
$variables = array_merge($default, $_POST);
Upvotes: 0
Reputation: 23542
Try this:
echo file_get_contents("php://input");
Normal parameters you can get with
parse_str(file_get_contents("php://input"), $_POST);
for name you have to parse it yourself.
$a = explode('$', file_get_contents("php://input"));
Upvotes: 0
Reputation: 191
curl -d "id=1&name=&age=12" http://localhost/post.php
should do the trick
Upvotes: 1