ReLIFE 重返17歲 ReLIFE 重返17歲 mobile
                getComicHtml($url);
                        $comicHtml = str_get_html($comicHtmlStr);
                        $area = $comicHtml->find('div[class=chapter-list]');
                
                        # 取得所有的話數 url
                
                        echo strlen($comicHtml);
                        echo 'done';
                    }
                
                    private function getComicHtml($urlComic)
                    {
                        # 拆解 URL
                        $urlAry = explode('/', $urlComic);
                        $index = count($urlAry);
                        $lastNum = $index - 2;
                        #
                        $tmpName = 'tmp' . $urlAry[$lastNum];
                        # 判定暫存
                        if(!file_exists($tmpName))
                        {
                            # 儲存暫存
                            $html = $this->getUrlHtml($urlComic);
                            $fp = fopen($tmpName, 'w+');
                            fwrite($fp, $html);
                            fclose($fp);
                            echo 'do';
                        }
                
                        # 讀取暫存
                        $fileStr = file_get_contents($tmpName);
                        return $fileStr;
                    }
                
                    private function getImgUrl($url, $path)
                    {
                        $pageStr = $this->getUrlHtml($url);
                        $pageHtml = str_get_html($pageStr);
                        
                        $imgObj = $pageHtml->find('div[id^=cc-m-gallery-]', 0);
                        $aAry = $imgObj->find('a');
                        foreach($aAry as $k=>$a)
                        {
                            # 圖片
                            $imgOrg = $a->getAttribute('data-href');
                            $img90 = $a->find('img', 0)->getAttribute('src');
                            
                            $imgname = str_pad($k, 3, "0", STR_PAD_LEFT) . basename($imgOrg);
                            $this->saveImg($imgOrg, $path, $imgname );
                            $this->saveImg($img90, $path.'90/', $imgname );
                        }
                    }
                
                    // 儲存圖片
                    private function saveImg($imgUrl, $path, $imgName)
                    {
                        if(!file_exists($path)){
                            mkdir($path, 0777, true);
                        }
                        if(!file_exists($path . $imgName)){
                            $ch = curl_init($imgUrl);
                            $fp = fopen( $path . $imgName, 'wb');
                            curl_setopt($ch, CURLOPT_FILE, $fp);
                            curl_setopt($ch, CURLOPT_HEADER, 0);
                            curl_exec($ch);
                            curl_close($ch);
                            fclose($fp);
                        }
                    }
                }
                
                $d = new Download();
                $d->index();
                ?>