bencode full decoding implemented: integers, lists, dictionaries and strings
This commit is contained in:
parent
142cc44dc9
commit
15a90639e1
1 changed files with 13 additions and 0 deletions
13
bencoder.php
13
bencoder.php
|
|
@ -62,6 +62,19 @@ function bdecode($enc, &$off = null)
|
||||||
while (substr($enc, $off, 1) != 'e') {
|
while (substr($enc, $off, 1) != 'e') {
|
||||||
array_push($result, bdecode($enc, $off));
|
array_push($result, bdecode($enc, $off));
|
||||||
}
|
}
|
||||||
|
} else if ($type == 'd') {
|
||||||
|
$off++;
|
||||||
|
$result = array();
|
||||||
|
while (substr($enc, $off, 1) != 'e') {
|
||||||
|
$key = bdecode($enc, $off);
|
||||||
|
$value = bdecode($enc, $off);
|
||||||
|
$result[$key] = $value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sep = strpos($enc, ':', $off);
|
||||||
|
$len = intval(substr($enc, $off, $sep - $off));
|
||||||
|
$result = substr($enc, $sep + 1, $len);
|
||||||
|
$off = $sep + 1 + $len;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue