我正在设置一个新服务器,并希望在我的Web应用程序中完全支持UTF-8.我过去曾在现有的服务器上尝试过此操作,但最终似乎不得不回归ISO-8859-1.
我在哪里需要设置编码/字符集?我知道我需要配置Apache,MySQL和PHP来执行此操作 - 是否有一些我可以遵循的标准清单,或者可能是在出现不匹配的地方进行故障排除?
这适用于运行MySQL 5,PHP,5和Apache 2的新Linux服务器.
什么列类型应该用于在mysql数据库中存储序列化数据?我知道你可以使用varbinary,blob,text.什么被认为是最好的,为什么?
编辑:我知道存储序列化数据并不"好".我需要在这一个案例中做到这一点.如果你有答案,请相信我,并专注于这个问题.谢谢!
我有一个由PHP序列化的大型多维数组.它已存储在MySQL中,并且数据字段不够大......结束已被切断...我需要提取数据...... unserialize不会工作...有没有人知道可以关闭的代码所有的数组...重新计算字符串长度...手工做的数据太多了.
非常感谢.
我们在使用PHP序列化/反序列化时遇到了一个奇怪的问题.我们已经序列化并存储在mysql中的特定字符串中(UTF-8整理).反序列化时会返回错误.
例如:字符串:
"Anoop很好地剪下了以P字母开头的杂志中的图片."
DB中的序列化数据:
s:96:"Anoop很好地剪掉了以P字母开头的杂志中的照片."
虽然反序列化我们得到了这个错误Notice - unserialize (): Error at offset 2 of 101 bytes.我们注意到字符串长度不同.这个问题的原因是什么?
任何帮助将非常感激.谢谢!
我试图通过html格式的输入字段传递数组.使用序列化传递它然后反序列化再次读取数组.我有多个输入字段.
$test = array('name' => 'Sander', 'type' => 'melon');
echo '<input type="hidden" name="rank[]" value="'.serialize($test).'" >';
Run Code Online (Sandbox Code Playgroud)
然后,如果我想反序列化并显示数据,则会出错:
$list = $_POST['rank'];
var_dump($list);
var_dump(unserialize($list[0]));
Run Code Online (Sandbox Code Playgroud)

我在网站上使用laravel缓存(remember()方法),代码如下:
$postedItems = Cache::remember('home_posted_items', $this->cacheTimes['postedItems'], function() {
/* the stuff that prepares data */
return ['items' => $items, 'firstItemNumber' => $firstItem];
});
Run Code Online (Sandbox Code Playgroud)
问题是,有时(每隔几天,我会说)缓存文件似乎已损坏,因此我有停机时间,直到缓存过期(除非我手动清除它).
以下是可能相关的错误堆栈的一部分:
[2017-02-04 22:01:34] production.ERROR: ErrorException: unserialize(): Error at offset 131059 of 131062 bytes in /home/path/to/app/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php:78
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'unserialize(): ...', '/home/path/to/...', 78, Array)
#1 /home/path/to/app/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php(78): unserialize('a:2:{s:7:"item...')
#2 /home/path/to/app/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php(47): Illuminate\Cache\FileStore->getPayload('home_posted_ite...')
#3 /home/path/to/app/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(98): Illuminate\Cache\FileStore->get('home_posted_ite...')
#4 /home/path/to/app/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(202): Illuminate\Cache\Repository->get('home_posted_ite...')
#5 [internal function]: Illuminate\Cache\Repository->remember('home_posted_ite...', 1, Object(Closure))
#6 /home/path/to/app/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(318): call_user_func_array(Array, Array)
#7 /home/path/to/app/bootstrap/cache/compiled.php(6089): Illuminate\Cache\CacheManager->__call('remember', Array)
#8 /home/path/to/app/app/Http/Controllers/HomeController.php(197): Illuminate\Support\Facades\Facade::__callStatic('remember', …Run Code Online (Sandbox Code Playgroud) 我有Drupal 6.20的问题.
可能在PHP更新后,站点停止工作.我明白了:
Notice: unserialize() [function.unserialize]: Error at offset 0 of 22765 bytes in /PATH/includes/cache.inc on line 33
Run Code Online (Sandbox Code Playgroud)
这是一行:
$cache->data = unserialize($cache->data);
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助.
在将对象存储到数据库之后,我在网站上有许多偏移错误,而不是检索它.如果我不存储它一切正常:
$serializedObject = serialize($this);
$unSerializedObject = unserialize($serializedObject);
Run Code Online (Sandbox Code Playgroud)
此外,我在保存数据并从数据库中检索数据时使用base64编码,但这没有用.我不做任何逃避.我的对象处理一些字符串.我发现的是这个字符串:
A woman is travelling around the world. She is 28 years old and she is from Great Britain.
She cannot use a car or a plane on her
Run Code Online (Sandbox Code Playgroud)
它工作正常.但是当我添加一个空格和单词[旅程]时,错误会弹出.这是带有这个单词的字符串:
A woman is travelling around the world. She is 28 years old and she is from Great Britain.
She cannot use a car or a plane on her journey
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么弹出错误?
这是serialize($this)没有单词的文本运行的输出journey
以下是serialize($this)使用单词对文本运行的输出journey
UPDATE
我保存对象的表有charset utf-8 …
我orders使用该serialize方法将我的购物车数据保存到表中,现在在我的订单“查看”页面中,我想向用户显示它们以显示他们的订单历史记录。
如何将以前序列化的数据恢复为 PHP 中的可用对象/数组?
我保存数据的代码片段:$order->cart = serialize($cartItems);.
我尝试返回我的订单索引视图的方法:
/**
* Action to receive all orders from the current
* logged-in user. This action will return the
* 'front.orders' view with the orders compacted inside.
*
* @return orders view
*/
public function orders() {
// get the orders from the current logged in user
$orders = Order::where('user_id', '=', Auth::user()->id)->get();
// view the `front.orders` page passing in the `orders` variable
return view('front.orders', compact('orders'));
}
Run Code Online (Sandbox Code Playgroud) 我在尝试反序列化数据时遇到错误.发生以下错误:
unserialize(): Error at offset 46 of 151 bytes
Run Code Online (Sandbox Code Playgroud)
这是序列化数据:
s:151:"a:1:{i:0;a:4:{s:4:"name";s:15:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}";
Run Code Online (Sandbox Code Playgroud)
该错误是由数据中的单引号引起的.当我正在使用的站点和数据库已经存在时,如何缓解此问题?不幸的是,我无法重写负责序列化和将数据插入数据库的代码.整个数据库很可能出现此问题.
有没有我可以用来逃避数据的函数?
我试图反序列化一个序列化的字符串:
$sri = 'a:8:{s:3:"key";s:32:"73b43c7df3604c8d725f856b219cffda";s:5:"email";s:19:"Aligh.Pro@gmail.com";s:4:"date";s:0:"";s:9:"user_info";a:4:{s:2:"id";i:2;s:5:"email";s:19:"Aligh.Pro@gmail.com";s:10:"first_name";s:5:"mahdi";s:8:"discount";s:4:"none";}s:9:"downloads";a:1:{i:0;a:3:{s:2:"id";i:44;s:8:"quantity";i:1;s:7:"options";a:2:{s:8:"quantity";i:1;s:8:"price_id";s:1:"1";}}}s:12:"cart_details";a:1:{i:0;a:10:{s:4:"name";s:17:"?????? ??";s:2:"id";i:44;s:11:"item_number";a:3:{s:2:"id";i:44;s:8:"quantity";i:1;s:7:"options";a:2:{s:8:"quantity";i:1;s:8:"price_id";s:1:"1";}}s:10:"item_price";d:20000;s:8:"quantity";i:1;s:8:"discount";d:0;s:8:"subtotal";d:20000;s:3:"tax";d:0;s:4:"fees";a:0:{}s:5:"price";d:20000;}}s:4:"fees";a:0:{}s:8:"currency";s:4:"RIAL";}';
$data_array = unserialize((string) $sri);
echo '<pre>';
print_r($data_array);
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)
但我看到了这个错误:注意:unserialize(): Error at offset 438 of 750 bytes in ...
我通过在线反序列化尝试了上面的序列化字符串。字符串工作得很好。但在我的电脑中,它没有。
有什么问题?
这工作 -
$serialized = 'a:23:{s:6:"fields";a:5:{s:21:"display_name_creditor";s:1:"1";s:24:"display_name_constituent";s:1:"1";s:14:"email_creditor";s:1:"1";s:14:"phone_creditor";s:1:"1";s:12:"total_amount";s:1:"1";}s:5:"id_op";s:2:"in";s:8:"id_value";a:0:{}s:21:"receive_date_relative";s:1:"0";s:17:"receive_date_from";s:0:"";s:15:"receive_date_to";s:0:"";s:25:"contribution_status_id_op";s:2:"in";s:28:"contribution_status_id_value";a:1:{i:0;s:1:"1";}s:16:"total_amount_min";s:0:"";s:16:"total_amount_max";s:0:"";s:15:"total_amount_op";s:3:"lte";s:18:"total_amount_value";s:0:"";s:6:"gid_op";s:2:"in";s:9:"gid_value";a:0:{}s:8:"tagid_op";s:2:"in";s:11:"tagid_value";a:0:{}s:11:"description";s:20:"Soft Credit details.";s:13:"email_subject";s:0:"";s:8:"email_to";s:0:"";s:8:"email_cc";s:0:"";s:10:"permission";s:21:"access CiviContribute";s:6:"groups";s:0:"";s:9:"domain_id";i:1;}';
Run Code Online (Sandbox Code Playgroud)
$ result = unserialize($ serialized);
这不 -
$serialized = 'a:23:{s:6:"fields";a:5:{s:21:"display_name_creditor";s:1:"1";s:24:"display_name_constituent";s:1:"1";s:14:"email_creditor";s:1:"1";s:14:"phone_creditor";s:1:"1";s:12:"amount";s:1:"1";}s:5:"id_op";s:2:"in";s:8:"id_value";a:0:{}s:21:"receive_date_relative";s:1:"0";s:17:"receive_date_from";s:0:"";s:15:"receive_date_to";s:0:"";s:25:"contribution_status_id_op";s:2:"in";s:28:"contribution_status_id_value";a:1:{i:0;s:1:"1";}s:16:"total_amount_min";s:0:"";s:16:"total_amount_max";s:0:"";s:15:"total_amount_op";s:3:"lte";s:18:"total_amount_value";s:0:"";s:6:"gid_op";s:2:"in";s:9:"gid_value";a:0:{}s:8:"tagid_op";s:2:"in";s:11:"tagid_value";a:0:{}s:11:"description";s:20:"Soft Credit details.";s:13:"email_subject";s:0:"";s:8:"email_to";s:0:"";s:8:"email_cc";s:0:"";s:10:"permission";s:21:"access CiviContribute";s:6:"groups";s:0:"";s:9:"domain_id";i:1;}'
Run Code Online (Sandbox Code Playgroud)
我刚刚将total_amount字段更改为amount,我收到此错误 -
unserialize(): Error at offset 181 of 849 bytes
Run Code Online (Sandbox Code Playgroud)
我已经检查了unserialize()[function.unserialize]提供的解决方案:offset和http://davidwalsh.name/php-serialize-unserialize-issues的错误,但没有任何效果.
也试过用 base64_encode/decode before serialize/unserialize
任何提示?