PHP unserialize fails with non-encoded characters?

后端 未结 14 1728
遥遥无期
遥遥无期 2020-11-27 16:13
$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 = un         


        
14条回答
  •  眼角桃花
    2020-11-27 16:58

    One more slight variation here which will hopefully help someone ... I was serializing an array then writing it to a database. On retrieving the data the unserialize operation was failing.

    It turns out that the database longtext field I was writing into was using latin1 not UTF8. When I switched it round everything worked as planned.

    Thanks to all above who mentioned character encoding and got me on the right track!

提交回复
热议问题