Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter中获取输入表单的json值_Php_Json_Codeigniter - Fatal编程技术网

Php 如何在codeigniter中获取输入表单的json值

Php 如何在codeigniter中获取输入表单的json值,php,json,codeigniter,Php,Json,Codeigniter,我有一个json变量,我想以json格式发布它 $json_value = json_encode($my_array); ... echo '<input name="myvalue" type="hidden" value="'.$json_value.'" />'; ... 但它是空的 我的表单工作正常,因为我可以获取其他输入值。将您的输入更改为使用单引号 echo "<input name='myvalue' type='hidden' value='$json_v

我有一个
json
变量,我想以
json
格式发布它

$json_value = json_encode($my_array);
...
echo '<input name="myvalue" type="hidden" value="'.$json_value.'"  />';
...
但它是空的


我的
表单
工作正常,因为我可以获取其他输入值。

将您的输入更改为使用单引号

echo "<input name='myvalue' type='hidden' value='$json_value'  />";
echo”“;

由于您在内部使用双引号,
$json\u value
也有双引号,因此存在冲突。
json\u encode
编码值有引号。因此,当第一个引号出现时,隐藏元素值将中断。还有一些其他方法可以使用表单发送php数组。我在这里添加了一个方法

//On html side
foreach($my_array as $value) {
    echo '<input name="myvalue[]" type="hidden" value="'.$value.'"  />';
}

//On posted server side
$posts = $this->input->post();
$my_array = $posts['myvalue']; //<-- you can get your array here
//在html端
foreach($my_数组作为$value){
回声';
}
//在服务器端
$posts=$this->input->post();

$myu数组=$posts['myvalue']//您可以显示您的
$json\u值
内容吗?您可以使用
base64\u encode()
而不是
json\u encode()
//On html side
foreach($my_array as $value) {
    echo '<input name="myvalue[]" type="hidden" value="'.$value.'"  />';
}

//On posted server side
$posts = $this->input->post();
$my_array = $posts['myvalue']; //<-- you can get your array here