把种子放到PHP同目录,种子名是filename.torrent 访问即可。
test.phpinclude 'BEncode.php';
include 'BDecode.php';
$torrent_content = file_get_contents('filename.torrent');
$desc = BDecode($torrent_content);
$info = $desc['info'];
$hash = strtoupper(sha1( BEncode($info) ));
sprintf('magnet:?xt=urn:btih:%s&dn=%s', $hash, $info['name']);
BEncode.php
class BEncode {
// Dictionary keys must be sorted. foreach tends to iterate over the order
// the array was made, so we make a new one in sorted order.
function makeSorted($array) {
// Shouldn't happen!
if (empty($array))
return $array;
$i = 0;
foreach($array as $ke