bdecode first test
This commit is contained in:
parent
53b4985869
commit
31aa07530a
1 changed files with 16 additions and 16 deletions
30
bencoder.php
30
bencoder.php
|
|
@ -42,23 +42,23 @@ function bencode($var)
|
||||||
do_error('bencode wrong data type');
|
do_error('bencode wrong data type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
function bdecode($enc)
|
function bdecode($enc)
|
||||||
{
|
{
|
||||||
if ($endPos = strpos($enc, 'e') == false) {
|
$result = null;
|
||||||
// string
|
$encLen = strlen($enc);
|
||||||
}
|
for ($i = 0; $i < $encLen; $i++)
|
||||||
if (!$endPos) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = substr($enc, 1, 1);
|
|
||||||
$data = substr($enc, 1, $endPos - 1);
|
|
||||||
switch ($type)
|
|
||||||
{
|
{
|
||||||
case 'i': return intval($data);
|
$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