简体   繁体   English

在数据库laravel中保存utf-8数组

[英]Saving utf-8 array in database laravel

I have problem with saving utf-8 array in database with laravel. 我在使用laravel在数据库中保存utf-8数组时遇到问题。 when i save array in database it is stored like this 当我在数据库中保存数组时,它就像这样存储

\u10e4\u10dd\u10dd\u10d3

when i display data it works fine, but when i run search query it displays nothing. 当我显示数据它工作正常,但当我运行搜索查询时,它什么也没显示。 database encoding is utf-8 with general_ci collation. 数据库编码是utf-8 with general_ci collat​​ion。 i've already tried to encode data before saving in database 我已经尝试在保存到数据库之前对数据进行编码

json_encode($data, JSON_UNESCAPED_UNICODE);

any ideas? 有任何想法吗?

Try storing these arrays in your database using the PHP serialize function instead of encoding for JSON. 尝试使用PHP 序列化函数将这些数组存储在数据库中,而不是使用JSON编码。

serialize($data);

When you want to use the data back, simply deserialize the array with PHP unserialize function. 当您想要使用数据时,只需使用PHP unserialize函数反序列化数组。

unserialize($data);

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

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