Нет, только в заданной директории. Прийдется по очереди парсить, просто новый путь указать до подпапки и новый файл для записи, так как он перезапишет данные, если в тот же файл парсить. Или вместо парметра mode "wb" напиши "ab", тогда при парсинге подпапки данные добавятся в result.txt
ок с етим понятно.. чтот не пашет запускаю хочу спарсить вк. в резулте в логе регулярка Code: ("#URL:.*http://login.vk.com.*\s(email: .*\pass: .*) где ошибка?
PHP: <?php set_time_limit(0); function file_parsing($dir) { global $result; $file_list = ''; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$dir}\\{$file}"; if (is_file($current_file)) { $file = file_get_contents($current_file); preg_match_all("#URL:.*vk.com.*\s(email:.*\spass:.*)#", $file, $match); if (count($match[1])>0) { $result .= implode('', $match[1])."\n"; } } } } } } $path = "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки file_parsing($path); $fp = fopen("result.txt", "wb");//Спарсенные даные будут лежать в result.txt fwrite($fp, "vk.com:\n".trim($result)); fclose($fp); ?> Теперь должно нормально парсить
хм... что-то не могу сообразить почему не ищет. вопрос глупый, но ты уверен, что в этой папке есть лог с данными: URL: http://login.vk.com email: 375299461870 pass: 10uыв
Если пробелы идут так: Code: URL: http://login.vk.com email: helga.krivko@tut.by pass: Красавица то конечно не найдет
PHP: <?php set_time_limit(0); function file_parsing($dir) { global $result; $file_list = ''; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$dir}\\{$file}"; if (is_file($current_file)) { $file = file_get_contents($current_file); preg_match_all("#URL:.*vk.com.*\s+(email:.*\s+pass:.*)#", $file, $match); if (count($match[1])>0) { $result .= implode('', $match[1])."\n"; } } } } } } $path = "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки file_parsing($path); $result = preg_replace("# #", "", $result); $fp = fopen("result.txt", "wb");//Спарсенные даные будут лежать в result.txt fwrite($fp, "vk.com:\n".trim($result)); fclose($fp); ?>
ура наконецто)) как тепреь избавится от лишнего? нужно убрать email: и pass: чтото кручу кручу. или не парсит или парсит так
Поможет превратить логи вида: в такой: PHP: <?php $h = fopen("in.txt", "r"); $h1 = fopen("out.txt", "a+"); while(($buf = fgets($h)) !== false) { if(preg_match('/^.+?@+(.+?:.+?)$/', $buf, $m)) { fwrite($h1, $m[1]."\r\n"); } } fclose($h); fclose($h1); ?>
Лень переделывать регэксп. Сделал так: PHP: <?php set_time_limit(0); function file_parsing($dir) { global $result; $file_list = ''; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$dir}\\{$file}"; if (is_file($current_file)) { $file = file_get_contents($current_file); preg_match_all("#URL:.*vk.com.*\s+(email:.*\s+pass:.*\s)#", $file, $match); print_r($match); if (count($match[1])>0) { $result .= implode('', $match[1])."\n"; } } } } } } $path = "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки file_parsing($path); $result = preg_replace("# #", "", $result); $arr = explode("\n", $result); foreach ($arr as $line) { $res .= substr($line, strpos($line, ":")+1); } $fp = fopen("result.txt", "wb");//Спарсенные даные будут лежать в result.txt fwrite($fp, "vk.com:\n".trim($res)); fclose($fp); ?>
Ты бы сразу сказал как ты хочешь, а то так переделывать еще долго и нудно можно. PHP: <?php set_time_limit(0); function file_parsing($dir) { global $result; $file_list = ''; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$dir}\\{$file}"; if (is_file($current_file)) { $file = file_get_contents($current_file); preg_match_all("#URL:.*vk.com.*\s+email:(.*)\s+pass:(.*)#", $file, $match); if (count($match[1])>0) { for ($i=0; $i<count($match[1]); $i++) { $result .= trim($match[1][$i]).":".trim($match[2][$i])."\n"; } } } } } } } $path = "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки file_parsing($path); $result = preg_replace("# #", "", $result); $fp = fopen("result.txt", "wb");//Спарсенные даные будут лежать в result.txt fwrite($fp, "vk.com:\n".trim($result)); fclose($fp); ?>