种子读取php,php读取torrent种子文件内容的方法(测试可用),_PHP教程
php读取torrent种子文件内容的方法(测试可用),
本文实例讲述了php读取torrent种子文件内容的方法。分享给大家供大家参考,具体如下:
stack, array($this->y, $this->z, $this->m, $this->n, $this->stat));
list($this->y, $this->z, $this->m, $this->n, $this->stat) = array($newY, 0, 0, 0, $newStat);
}
/**
* This method restore the saved status of current
* encode/decode work.
*/
protected function pop()
{
$t = array_pop($this->stack);
if ($t) {
if ($t[4] == self::READ_DICT) {
$t[0]->{$t[1]} = $this->y;
$t[1] = 0;
} elseif ($t[4] == self::READ_LIST)
$t[0][] = $this->y;
list($this->y, $this->z, $this->m, $this->n, $this->stat) = $t;
}
}
/**
* This method initializes the status of work.
* YOU SHOULD CALL THIS METHOD BEFORE EVERYTHING.
*/
public function init()
{
$this->stat = self::READY;
$this->stack = array();
$this->z = $this->m = $this->n = 0;
}
/**
* This method decode $s($l as length).
* You can get $obj->y as the result.
*/
public function decode($s, $l)
{
$this->y = 0;
for ($i = 0; $i stat) {
case self::READY:
if ($s[$i] == 'd') {
$this->y = new xBDict();
$this->stat = self::READ_DICT;
} elseif ($s[$i] == 'l') {
$this->y = array();
$this->stat = self::READ_LIST;
}
break;
case self::READ_INT:
if ($s[$i] == 'e') {
$this->y->val = substr($s, $this->m, $i - $this->m);
$this->pop();
}
break;
case self::READ_STR:
if (xBInt::isNum($s[$i]))
continue;
if ($s[$i] = ':') {
$this->z = substr($s, $this->m, $i - $this->m);
$this->y = substr($s, $i + 1, $this->z + 0);
$i += $this->z;
$this->pop();
}
break;
case self::READ_KEY:
if (xBInt::isNum($s[$i]))
continue;
if ($s[$i] = ':') {
$this->n = substr($s, $this->m, $i - $this->m);
$this->z = substr($s, $i + 1, $this->n + 0);
$i += $this->n;
$this->stat = self::READ_DICT;
}
break;
case self::READ_DICT:
if ($s[$i] == 'e') {
$this->pop();
break;
} elseif (!$this->z) {
$this->m = $i;
$this->stat = self::READ_KEY;
break;
}
case self::READ_LIST:
switch ($s[$i]) {
case 'e':
$this->pop();
break;
case 'd':
$this->push(new xBDict(), self::READ_DICT);
break;
case 'i':
$this->push(new xBInt(), self::READ_INT);
$this->m = $i + 1;
break;
case 'l':
$this->push(array(), self::READ_LIST);
break;
default:
if (xBInt::isNum($s[$i])) {
$this->push('', self::READ_STR);
$this->m = $i;
}
}
break;
}
}
$rtn = empty($this->stack);
$this->init();
return $rtn;
}
/**
* This method encode $obj->y into BEncode.
*/
public function encode()
{
return $this->_encDo($this->y);
}
protected function _encStr($str)
{
return strlen($str) . ':' . $str;
}
protected function _encDo($o)
{
if (is_string($o))
return $this->_encStr($o);
if ($o instanceof xBInt)
return 'i' . $o->val . 'e';
if ($o instanceof xBDict) {
$r = 'd';
foreach ($o as $k => $c)
$r .= $this->_encStr($k) . $this->_encDo($c);
return $r . 'e';
}
if (is_array($o)) {
$r = 'l';
foreach ($o as $c)
$r .= $this->_encDo($c);
return $r . 'e';
}
}
}
class xBDict
{
}
class xBInt
{
public $val;
public function __construct($val = 0)
{
$this->val = $val;
}
public static function isNum($chr)
{
$chr = ord($chr);
if ($chr = 48)
return true;
return false;
}
}
//使用实例
$s = file_get_contents("test.torrent");
$bc = new xBEncoder();
$bc->init();
$bc->decode($s, strlen($s));
var_dump($bc->y);
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数组(Array)操作技巧大全》、《PHP数学运算技巧总结》、《PHP图形与图片操作技巧汇总》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
www.bkjia.comtrueTechArticlephp读取torrent种子文件内容的方法(测试可用), 本文实例讲述了php读取torrent种子文件内容的方法。分享给大家供大家参考,具体如下: php…
种子读取php,php读取torrent种子文件内容的方法(测试可用),_PHP教程相关推荐
- php格式的种子,php读取torrent种子文件内容的方法(测试可用)
本文实例讲述了php读取torrent种子文件内容的方法.分享给大家供大家参考,具体如下: /** * Class xBEncoder * Author: Angus.Fenying * Versio ...
- php获取种子失败,php读取BT种子文件内容的方法
这篇文章主要介绍了php读取BT种子文件内容的方法,可实现读取并显示BT种子文件内容的功能,简单实用.需要的朋友可以参考下.希望对大家有所帮助. 具体如下:<?php /** * Class x ...
- python 四种逐行读取文件内容的方法
目录 方法一:readline函数 方法二:一次读取多行数据 方法三:直接for循环 方法四:使用fileinput模块 下面是四种Python逐行读取文件内容的方法, 并分析了各种方法的优缺点及应用 ...
- python 读取文件读出来是什么格式-深入学习python解析并读取PDF文件内容的方法...
这篇文章主要学习了python解析并读取PDF文件内容的方法,包括对学习库的应用,python2.7和python3.6中python解析PDF文件内容库的更新,包括对pdfminer库的详细解释和应 ...
- python中读取文件内容-深入学习python解析并读取PDF文件内容的方法
这篇文章主要学习了python解析并读取PDF文件内容的方法,包括对学习库的应用,python2.7和python3.6中python解析PDF文件内容库的更新,包括对pdfminer库的详细解释和应 ...
- python读取文件多行内容-Python逐行读取文件内容的方法总结
Python四种逐行读取文件内容的方法 下面四种Python逐行读取文件内容的方法, 分析了各种方法的优缺点及应用场景,以下代码在python3中测试通过, python2中运行部分代码已注释,稍加修 ...
- 教大家python读取一行一行文件内容的方法
Python中readline()每次读取文件中的一行,需要使用永真表达式循环读取文件.但当文件指针移动到文件的末尾时,依然使用readline()读取文件将出现错误.因此程序中需要添加1个判断语句, ...
- python遍历文件内容_Python四种逐行读取文件内容的方法
下面是四种Python逐行读取文件内容的方法, 并分析了各种方法的优缺点及应用场景,以下代码在python3中测试通过, python2中运行部分代码已注释,稍加修改即可. 方法一:readline函 ...
- python怎么读取pdf文件_Python解析并读取PDF文件内容的方法
本文实例讲述了Python解析并读取PDF文件内容的方法.分享给大家供大家参考,具体如下: 一.问题描述 利用python,去读取pdf文本内容. 二.效果 三.运行环境 python2.7 四.需要 ...
最新文章
- XT910开通了GPRS却上不了网的原因--“数据漫游”功能关闭导致的
- Java wait forever_彻底搞清楚Java并发 (一) 基础
- rabbitmq的启动命令和springboot整合使用rabbitmq
- boost::spirit模块实现将由某个分隔符分隔的任意键/值对解析为 std::vector的测试程序
- Apache Camel中的短重试与长重试
- hdu5692 Snacks dfs序+线段树
- Keras-2 Keras Mnist
- 奥飞娱乐:贝肯熊和镇魂街盲盒产品计划于2021年下半年上市
- Volley源码学习1--volley结构图
- Domino邮件服务器防垃圾邮件中转
- 雅虎JavaScript架构师:网页开发技术安全优先
- 能同时模拟键盘及鼠标的神器--51单片机可控制
- Acme CAD Converter 的线宽要怎么设置啊
- C++入门教程(四十二):函数参数使用引用
- 第25章 燕尾蝶1
- 行业认证标准:PCI DSS - 支付卡行业数据安全标准
- acm CodeForces 546A
- Pthon.习题二 字符串的基本处理
- 【个人感悟】如何学习计算机知识
- 7-3 求最大值 (10 分)
热门文章
- 从零学习VH6501(七) —— Bus Off 的基本理解和测试用例设计
- 详解“未能确定工厂的发运数据”原因
- JavaScript 【库】测试题
- 日内期货交易系统,高手做交易独门策略系统
- Python 字符串格式化方法
- 2022届安防展观展所感所悟
- Depth Ranging Performance Evaluation and Improvement for RGB-D Cameras(提升深度测距的性能)
- 中国地方游戏网游戏大厅 v2.0 官方
- Regression----李宏毅
- Android培训全面课程(32天实战课程)