繁体   English   中英

如何从php变量对象中检索值

[英]How to Retrieve Value from a php variable object

我在PHP中返回了值$_POST['upload-picture']

[{"file":"0:/desert.jpg"}]

我不知道如何从这种格式检索上传图片的名称。 我尝试了很多事情,但仍然没有到达目的地。

有人可以帮忙吗?

假设$data具有值;

$data = [{"file":"0:/desert.jpg"}];
$array_data = json_decode($data[0], true);
echo $array_data['file'];  // This will print name of the image file.

您需要使用json_decode()解码数据,然后对其进行explode()以获得所需的名称:-

$image_array = json_decode($_POST['upload-picture'][0], true);

$final_image_name = explode('/',$image_array['file'])[1];

echo $final_image_name;

输出: -https : //eval.in/1003521

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM