gpt4 book ai didi

php - 删除json中的括号?

转载 作者:可可西里 更新时间:2023-11-01 12:25:42 24 4
gpt4 key购买 nike

json处理如何去掉下面的括号?

[{"success":true,"filename":"bialding_and_rebialding_plymouth02.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth03.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth04.jpg"}]

上面的结果被下面的类处理成一个数组,

function handle_upload($upload_directory)
{
# Loop the code according to the number of files.
for($i = 1; $i <= $this->total; $i++)
{
...

if ($this->file->save($upload_directory.$name_filtered.'.'.$file_extension , $i-1))
{
$message[] = array('success'=>true,'filename'=>$name_filtered.'.'.$file_extension);
}
else
{
$message[] = array('error'=> 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered');
}
}

return $message;
}

然后我用json_encode把数组转成json格式,

$uploader = new uploader();
$result = $uploader->handle_upload('uploads/');

echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);

但我只需要在我的结果中不带括号,

{"success":true,"filename":"bialding_and_rebialding_plymouth02.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth03.jpg"},{"success":true,"filename":"bialding_and_rebialding_plymouth04.jpg"}

最佳答案

str_replace(array('[', ']'), '', htmlspecialchars(json_encode($result), ENT_NOQUOTES)); ?

关于php - 删除json中的括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7109424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com