Показать сообщение отдельно

  #618  
Старый 10.02.2009, 08:48
KATYA
Участник форума
Регистрация: 09.02.2009
Сообщений: 229
Провел на форуме:
2856245

Репутация: 338
По умолчанию

Простенький генератор дорвеев. Создаёте две папки out и tpl, в первой будут сгенерированные страницы, а в tpl должен лежать шаблон генерируемой страницы. Скрипт работает и с русскими ключевыми словами.

index.php
PHP код:
<?php    if ($_POST['generate']) {      generate();  }else {      main_form();  }        function generate() {      $p=array();      if ($_POST['tpl'] && $_POST['keywords']) {          $_POST['keywords']=ereg_replace("(\r\n|\r)","\n",$_POST['keywords']);          $keys=explode("\n",trim($_POST['keywords']));            /* create pages array */          for($i=0;$i<intval($_POST['count']);$i++) {              list($k,$v)=each($keys);              if (!$v) {                  reset($keys);                  list($k,$v)=each($keys);              }              if (in_array(trim($v),$p)) {                  $v=trim($v).'_'.$i;              }              $p[]=trim($v);          }                      /* prepare template */          $tpl=implode('',file('./tpl/'.$_POST['tpl']));            /* generate links */          $z=1;          reset($p);          while(list($k,$v)=each($p)) {              $name=str_replace(' ','_',$v);              $l.='<a href="'.trim($z++).'.html">'.trim($v).'</a> ';          }            /* generate pages */          reset($p);          while(list($k,$v)=each($p)) {              $k++;              $name=trim($k++);                $tpl_out=str_replace('{TITLE}',$v,$tpl);              $tpl_out=str_replace('{KEYWORDS}',ereg_replace("(\r\n|\n|\r)","",implode(', ',$keys)),$tpl_out);              $tpl_out=str_replace('{DESC}',ereg_replace("(\r\n|\n|\r)","",implode(' ',$keys)),$tpl_out);              $tpl_out=str_replace('{LINK}',$l,$tpl_out);              $tpl_out=str_replace('{I}',$k,$tpl_out);              $tpl_out=str_replace('{ENTER}',trim($_POST['enter']),$tpl_out);                $fp=fopen('./out/'.$name.'.html','w');              fwrite($fp,$tpl_out);              fclose($fp);              print 'pages created -> '.$name.'.html<br>';              flush();          }          print '<font size=7 color="#FF0000">Захуярено!</font>';      }else {          print 'Блядь! Шаблон и слова где ****? <br>';      }  }    function main_form() {      ?>      <table width="400" border="0" cellspacing="2" cellpadding="0" align="center">          <form action="" method="post">          <tr>              <td>Стараниц стока:</td>              <td><input type="text" name="count" size="5" maxlength="5" value="5"></td>          </tr>          <tr>              <td><br>Вот шаблон:<br><br><br></td>              <?php              $a=array();              if ($handle opendir('./tpl')) {                  while (false !== ($file readdir($handle))) {                      if ($file != "." && $file != ".." && is_file('./tpl/'.$file)) {                          $a[]=$file;                      }                  }                  closedir($handle);              }              ?>              <td><select name="tpl">                      <?php while(list($k,$v)=each($a)) {?>                      <option value="<?php print $v;?>"><?php print $v;?></option>                      <?php ?>                  </select>              </td>          </tr>          <tr>              <td><br>Куда потом:<br><br><br></td>              <td><input type="text" name="enter" size="40" value="http://"></td>          </tr>          <tr>              <td>Ключевые словишки:</td>              <td><br>  <textarea cols="30" rows="10" name="keywords">  слово  слово 2  и так далее  </textarea>              </td>          </tr>          <tr><td colspan="2"><input type="submit" name="generate" value="Захуярить!"></td></tr>          </form>      </table>      <?php  }    ?>
tpl.html

Код HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">  <html>  <head>  <title>{TITLE}</title>  <meta http-equiv="KEYWORDS" content="{KEYWORDS}">  <meta http-equiv="DESCRIPTION" content="{DESC}">  </head>  <body>  <br>  <br>  <br>  <div align="center"><a href="{ENTER}">ENTER</a></div>  <br>  <br>  <br>  <div align="center">{LINK}</div>  </body>  </html>
Разумеется index.php должен лежать в корне.
 
Ответить с цитированием