function getDirectoryListing($result, $path, $cat) { $path .= " > " . $cat; $cat = str_replace(" ", "_", $cat); $ch = curl_init(); $buffer = fopen("buffer.html", "w"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"); curl_setopt($ch, CURLOPT_URL, "http://ru.wikipedia.org/wiki/Категория:" . $cat); curl_setopt($ch, CURLOPT_FILE, $buffer); curl_exec($ch); curl_close($ch); fclose($buffer); // working with the pre-fetched page using DOMDocument // due to a bug (?) w/ fetching Cyrillic URLs via DOMDocument->loadHTMLFile $html = new DOMDocument(); $html->loadHTMLFile("buffer.html"); $subCats = $html->getElementById("mw-subcategories"); if ($subCats) { foreach ($subCats->getElementsByTagName("a") as $s) { getDirectoryListing($result, $path, $s->textContent); } unset($subCats); } $pages = $html->getElementById("mw-pages"); if ($pages) { foreach ($pages->getElementsByTagName("a") as $a) { fwrite($result, "{$path} > {$a->textContent}" . PHP_EOL); } unset($pages); } }
{ $a = array(); if ($handle = opendir($dir)) { $index = 0; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "CVS") { $a[$index] = $dir . "/" . $file; $index++; } } closedir($handle); return $a; } return NULL; } $d = getDirectoryListing("Download/Releases"); rsort($d); foreach ($d as $f) { ?> <a href="<?php echo $f; ?> "><?php echo basename($f); ?> </a><br> <?php } ?> </blockquote>