Download.php 625 B

12345678910111213141516171819202122232425262728293031323334
  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. $config = array('GB2312', 'GBK', 'EUC-CN', 'CP936');
  19. if (in_array($encode, $config)) {
  20. $string = iconv('GBK', 'UTF-8', $string);
  21. }
  22. /*
  23. if ($encode == 'CP936') {
  24. $string = iconv('SJIS', 'UTF-8', $string);
  25. }
  26. */
  27. $string = str_replace(PHP_EOL, '', $string);
  28. return $string;
  29. }
  30. }