Download.php 598 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Spider\Lib;
  3. use Dever;
  4. class Download
  5. {
  6. private $data;
  7. public function __construct($url)
  8. {
  9. $this->data = Dever::curl($url);
  10. }
  11. public function get()
  12. {
  13. return $this->filter($this->data);
  14. }
  15. private function filter($string)
  16. {
  17. $encode = mb_detect_encoding($string, array('GB2312','GBK','UTF-8'));
  18. if ($encode == 'GB2312' || $encode == 'GBK' || $encode == 'EUC-CN') {
  19. $string = \iconv('GBK', 'UTF-8', $string);
  20. }
  21. if ($encode == 'CP936') {
  22. $string = \iconv('SJIS', 'UTF-8', $string);
  23. }
  24. $string = str_replace(PHP_EOL, '', $string);
  25. return $string;
  26. }
  27. }