<?PHP /* * meifk * 2013/12/07 */ if(isset($_POST['url'])) { if(isset($_POST['project']) && !is_dir($_POST['project'])) mkdir($_POST['project'], 0777); echo json_encode(grab($_POST['url'])); } function grab($url) { //$url = 'http://themes.shamsoft.net/flaty/index.html'; $data = array(); $file = preg_replace('/^.*\//', '', $url); if(($content = file_get_contents($url)) !== false) { if(isset($_POST['project'])) file_put_contents($_POST['project'].'/'.$file, $content); $pattern = '/<link.*?href\=(\'|")(.*?\.css)\1.*?>/i'; if(preg_match_all($pattern, $content, $matches)) { $data['css'] = $matches[2]; } $pattern = '/<script.*?src\=(\'|")(.*?\.js)\1.*?>/i'; if(preg_match_all($pattern, $content, $matches)) { $data['js'] = $matches[2]; } $pattern = '/<img.*?src\=(\'|")(.*?)\1.*?>/i'; if(preg_match_all($pattern, $content, $matches)) { $data['img'] = $matches[2]; } $pattern = '/url\((\'|"|\s)(.*?)\1\)/i'; if(preg_match_all($pattern, $content, $matches)) { $data['src'] = $matches[2]; } } return $data; } function vardump($obj) { echo '<pre>'; print_r($obj); echo '</pre>'; } ?>