Bittorrent парсер (Bittorrent parser)
Code (php)
-
-
<?php
-
-
// bit torrent parser function by techtonik // php.net
-
-
-
$input = $argv[1];
-
-
-
function parse_torrent($s) {
-
static $str;
-
$str = $s;
-
-
// echo $str{0};
-
-
if ($str{0} == ‘d’) {
-
$key = parse_torrent($str);
-
$save = $str;
-
}
-
// echo ".",$str{0};
-
$value = parse_torrent($str);
-
}
-
-
// process hashes - make this stuff an array by piece
-
0, -4
-
)
-
);
-
};
-
$ret[$key] = $value;
-
}
-
return $ret;
-
} else if ($str{0} == ‘i’) {
-
// echo "_";
-
return $ret;
-
} else if ($str{0} == ‘l’) {
-
// echo "#";
-
$value = parse_torrent($str);
-
$ret[] = $value;
-
}
-
return $ret;
-
// echo "@";
-
return $name;
-
}
-
}
-
-
$bencode = parse_torrent($str);
-
-
