php - 如何删除数组前后的“”
问题描述
如何 " "
从数组开始和数组结束后删除。我只需要数组而不需要"
public function showPatientModal(Request $request)
{
$patient_id = $request->input('id');
$data['patient'] = Patient::with('cases')->where('id', $patient_id)->first();
$files_before = $data['patient']->file_before;
$files_after = $data['patient']->file_after;
dd($files_before);
}
将以下内容返回给我,但我将数组作为字符串获取
"["download (2).jpg","download (3).jpg","download.jpg"]"
解决方案
<?php
$string = '"["download (2).jpg","download (3).jpg","download.jpg"]"';
$string = preg_replace('/(?<=^)\s*"\s*(?=\[)/', '', preg_replace('/(?<=\])\s*"\s*(?=$)/', '', $string));
echo $string;
我没有对此进行测试,但它应该可以工作。
顺便说一句,如果你想将它传递给 javascript,你最好使用json_encode代替。
推荐阅读
- intellij-idea - 在 Intellij IDEA 中从查找返回到编辑器快捷方式
- c# - UWP / C# - 如何打印自定义页面大小
- c# - 无法建立 SSL 连接,请参阅内部异常
- mysql - 如何计算3个月前的到期日期将到期
- python - 查找协方差矩阵的特征值
- sql - 从 Firebird 的给定范围中选择日期列表
- python - Pygame 运行没有任何问题,但屏幕上没有绘制任何内容
- git - 如何在不影响以后的提交的情况下恢复旧的 Git 提交?
- javascript - 此 JS IIFE 是否正确传递事件处理程序的事件和参数?
- python - ImportError:无法导入名称“safe_join”