This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
我正在一个项目中,他们在mysql数据库的BLOB类型列中存储了以下类型的编码数据。我四处询问,并被告知这是Bencode,但是,据我在线所见,它似乎不是标准的Bencode。

Bencode的Wiki

http://en.wikipedia.org/wiki/Bencode

编码数据示例

a:11:{i:0;a:3:{s:11:"question_id";s:2:"46";s:6:"answer";s:1:"2";s:7:"correct";b:1;}i:1;a:3:{s:11:"question_id";s:2:"45";s:6:"answer";s:1:"2";s:7:"correct";b:0;}i:2;a:3:{s:11:"question_id";s:2:"44";s:6:"answer";s:1:"2";s:7:"correct";b:0;}i:3;a:3:{s:11:"question_id";s:2:"43";s:6:"answer";s:1:"1";s:7:"correct";b:0;}i:4;a:3:{s:11:"question_id";s:2:"42";s:6:"answer";s:1:"3";s:7:"correct";b:0;}i:5;a:3:{s:11:"question_id";s:2:"41";s:6:"answer";s:1:"2";s:7:"correct";b:0;}i:6;a:3:{s:11:"question_id";s:2:"40";s:6:"answer";s:1:"0";s:7:"correct";b:1;}i:7;a:3:{s:11:"question_id";s:2:"39";s:6:"answer";s:1:"0";s:7:"correct";b:0;}i:8;a:3:{s:11:"question_id";s:2:"38";s:6:"answer";s:1:"1";s:7:"correct";b:1;}i:9;a:3:{s:11:"question_id";s:2:"37";s:6:"answer";s:1:"3";s:7:"correct";b:0;}i:10;a:3:{s:11:"question_id";s:2:"36";s:6:"answer";s:1:"2";s:7:"correct";b:1;}}


到目前为止我所注意到的

我注意到,编码使用类似于Bencode的字母和整数描述了不同类型的数据。

例:
s:11:"question_id";

我假设s代表“字符串”,而11定义了字符串question_id的长度。同样,数据的开头(a:11:)似乎描述了一个长度为11的数组。尽管这与标准Bencode相似,但似乎并没有使用Bencode使用的标准语法。

有谁知道这是什么类型的编码?这是非标准的Bencode格式,还是完全不同?我正在寻找PHP或Python中的解析器,并且为编码指定名称肯定会对我的搜索有所帮助。

最佳答案

这是PHP序列化格式,无法使用unserialize进行序列化。
请参见http://codepad.org/l7Z9cITo

10-07 12:25