Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $numPages = 20; // количество страниц для генерации
- $resultExtension = '.html'; // расширение файлов результата
- $tplFile = 'tpl.txt'; // файл шаблона
- $keywordsFile = 'keywords.txt'; // файл с ключевиками
- $descFile = 'descriptions.txt'; // файл с десками
- $resultFolder = 'out'; // папка с результатом
- $numLinks = 10; // количество ссылок на другие страницы
- $keywords = $keywordsForLinks = array_reverse(file($keywordsFile));
- shuffle($keywordsForLinks);
- $descs = array_reverse(file($descFile));
- $tpl = file_get_contents($tplFile);
- // main loop
- for ($i = 0; $i < $numPages; $i++){
- $out = preg_replace_callback(
- '~%%%(keyword|description|links)%%%~',
- function ($m) {
- global $keywords, $descs, $numLinks, $keywordsForLinks;
- if ($m[0] == '%%%keyword%%%'){
- $r = trim(array_pop($keywords));
- }elseif($m[0] == '%%%description%%%'){
- $r = trim(array_pop($descs));
- }elseif($m[0] == '%%%links%%%'){
- $r = '<ul>';
- for ($i = 0; $i < $numLinks; $i++){
- $r .= '<li><a href="/'.$i.$resultExtension.'">'.trim($keywordsForLinks[array_rand($keywordsForLinks)]).'</a></li>';
- }
- $r .= '</ul>';
- }
- return empty($r) ? $m[0] : $r;
- },
- $tpl);
- if ($i == 0){
- $resultFileName = $resultFolder.'/index'.$resultExtension;
- }else{
- $resultFileName = $resultFolder.'/'.$i.$resultExtension;
- }
- $fp = fopen($resultFileName, "w+t");
- fwrite($fp, $out);
- fclose($fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement