早睡早起,方能养生
Sleep early rise early, way to keep healthy

PHP json_encode 存储textarea中带有回车的数据时,json_decode出错

super
2024-03-14 17:41
views 224

存:

 

$data = str_replace("\n", '<br>', $_POST['data']);
$data = str_replace("\r", '', $data);

$array = ['data' => $data];

json_encode($array, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
// 接下来插入数据库

 

 

取:

 

$array = json_decode($array, true);
foreach ($array as $key => $value) {
	$array[$key]['data'] = str_replace('<br>', '
', $value['data']);
}

 



分享
0 条讨论
top