123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace Spider\Lib;
- use Dever;
- class Queue
- {
- private $data = array();
- public function push($value, $key = 0, $num = 0)
- {
- if (strpos($value, '{') !== false && strpos($value, '}') !== false) {
- $this->preg($value, $num);
- } else {
- array_push($this->data, $value);
- }
- return true;
- }
- public function pop()
- {
- return array_shift($this->data);
- }
- private function preg($value, $num)
- {
- $pat = '/{(.*?)}/i';
- preg_match_all($pat, $value, $match);
- if (isset($match[1][0]) && $match[1][0]) {
- if ($num <= 0) $num = 1000;
- parse_str($match[1][0], $param);
- $this->page($param, $match[0][0], $value, $num);
- }
- }
- private function page($param, $replace, $value, $num)
- {
- if (isset($param['page'])) {
- for ($i = $param['page']; $i <= $num; $i++) {
- $url = str_replace($replace, $i, $value);
- $this->push($url);
- }
- } else {
- $this->push(str_replace($replace, '', $value));
- }
- }
- }
|