PHP unserialize fails with non-encoded characters?
Posted
by FFish
on Stack Overflow
See other posts from Stack Overflow
or by FFish
Published on 2010-05-17T22:52:20Z
Indexed on
2010/05/17
23:00 UTC
Read the original article
Hit count: 203
$ser = 'a:2:{i:0;s:5:"héllö";i:1;s:5:"wörld";}'; // fails
$ser2 = 'a:2:{i:0;s:5:"hello";i:1;s:5:"world";}'; // works
$out = unserialize($ser);
$out2 = unserialize($ser2);
print_r($out);
print_r($out2);
echo "<hr>";
But why?
Should I encode before serialzing than? How?
I am using Javascript to write the serialized string to a hidden field, than PHP's $_POST
In JS I have something like:
function writeImgData() {
var caption_arr = new Array();
$('.album img').each(function(index) {
caption_arr.push($(this).attr('alt'));
});
$("#hidden-field").attr("value", serializeArray(caption_arr));
};
© Stack Overflow or respective owner