晚上突然看到了自己以前做BT站的计划,于是写了这么一段代码: >>”; $len=intval($array[0]); $array[1]=substr($string,$pos); $returnValue=substr($array[1],1,$len); $string=substr($string,$len+strlen($array[0])+1); return $returnValue; } function &getNextInteger($string) { $a=”i”; $b=”e”; $start=strpos($string,$a); $end=strpos($string,$b); $integer= substr($string,$start+1,$end-$start-1); $string=substr($string,$end+1); return $integer; } function getStringFromAtoB($string,$a,$b) { $start=strpos($string,$a); $end=strpos($string,$b); return substr($string,$start+1,$end-$start-1); } function &nextStep($str) { /** 返回值的含议: e:结束一个列表或字典 i:开始一个整数 任一数字:开始一个字符串 */ $gotoNext=true; while($gotoNext) { if(!strlen($str)) { $gotoNext=false; break; } $firstChar=substr($str,0,1); switch($firstChar){ case “1”: case “2”: case “3”: case “4”: case “5”: case “6”: case “7”: case “8”: case “9”: case “0”: { $VARS[]=dictionary::getNextString(&$str); break; } case “i”: { $VARS[]=dictionary::getNextInteger(&$str); } case “e”: { break; } case “l”: case “d”: { $str=substr($str,1); $VARS[]=(dictionary::nextStep(substr($str,0,512))); // $VARS[]=dictionary::nextStep($str); $gotoNext=false; //$this->VARS[]=$this->nextStep($str); break; } default: $str=substr($str,1); $gotoNext=false; break; }//switch }//while return $VARS; } } ?> 最后可以返回一个这样的数组,这样就可以得到比如bt文件的文件名等等数据了。 Array ( [0] => Array ( [0] => announce [1] => http://tracker.icefish.org:8080/announce [2] => created by [3] => BitComet/0.59 [4] => creation date [5] => 1161189890 [6] => encoding [7] => GBK [8] => info [9] => Array ( [0] => length [1] => 408471635 [2] => name [3] => [bt.icefish.org]tonightlady20061017.rm [4] => name.utf-8 [5] => [bt.icefish.org]tonightlady20061017.rm [6] => piece length [7] => 262144 [8] => pieces [9] => ??** 注,这里是块数据,是二进制的,所以乱码很正常。。 ) ) )