bdecode first test
This commit is contained in:
parent
53b4985869
commit
31aa07530a
1 changed files with 16 additions and 16 deletions
32
bencoder.php
32
bencoder.php
|
|
@ -42,23 +42,23 @@ function bencode($var)
|
|||
do_error('bencode wrong data type');
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
function bdecode($enc)
|
||||
{
|
||||
if ($endPos = strpos($enc, 'e') == false) {
|
||||
// string
|
||||
}
|
||||
if (!$endPos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = substr($enc, 1, 1);
|
||||
$data = substr($enc, 1, $endPos - 1);
|
||||
switch ($type)
|
||||
{
|
||||
case 'i': return intval($data);
|
||||
|
||||
}
|
||||
$result = null;
|
||||
$encLen = strlen($enc);
|
||||
for ($i = 0; $i < $encLen; $i++)
|
||||
{
|
||||
$type = substr($enc, $i, 1);
|
||||
if ($type == 'i') {
|
||||
$start = ++$i;
|
||||
$end = strpos($enc, 'e', $i);
|
||||
$result = substr($enc, $start, $end - $start);
|
||||
$i = $end;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
*/
|
||||
|
||||
?>
|
||||
Loading…
Add table
Reference in a new issue