1. PHP / Говнокод #4212

    +150

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /* That revolting regular expression explained 
    /^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
      \---/  \---/\-------------/    \-------/
        |      |         |               |
        |      |         |           The value
        |      |    ~,|,^,$,* or =
        |   Attribute 
       Tag
    */

    Это НЕ говонокод, просто коммент к регулярке, просто очень понравился и хотел показать...
    Иногда регулярки очен запутанами бывает, и редактировать их турдно без нормальной комментов.
    Нашел в shop-script

    termes, 10 Сентября 2010

    Комментарии (16)
  2. PHP / Говнокод #4209

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    // $curr_page - старница, на который сейчас находимся
    // $n_page - число страниц
    // $count - обще число записей
    // $param - site - страницы на сайте
    //        - adm - в админке
    function genNumPage($curr_page, $n_page, $count, $param=null) {
        $string = parse_url($_SERVER['REQUEST_URI']);
        $query = '?'.$string['query'];
        $num_page = ceil($count / $n_page);
        if (isset($param))  $table = new my_Page("site/site_interface.html", "num_page");
        else                $table = new my_Page("interface/interface.html", "num_page");
        
        if ($num_page < 2) return null;
        
        for ($i = 1; $i <= $num_page; $i++) {
            if ($i != $curr_page) {
                if (preg_match('/\?p\=[0-9]{1,3}/', $query))        $href = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.$i, $query);
                elseif (preg_match('/\&p\=[0-9]{1,3}/', $query))    $href = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.$i, $query);
                elseif ($string['query'] != '')                     $href = '?'.$string['query'].'&p='.$i;
                else                                                $href = '?p='.$i;
                
                if ((!$param) || ($param == 'adm')) $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> ";
                else                                $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> | ";
            }
            elseif ((!$param) || ($param == 'adm')) $str .= "<span>".$i."</span>";
            else                                    $str .= "<span>".$i."</span> | ";
        }
        
            if ($curr_page > 1) {
            if (preg_match('/\?p\=[0-9]{1,3}/', $query))        $prev = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page - 1), $query);
            elseif (preg_match('/\&p\=[0-9]{1,3}/', $query))    $prev = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page - 1), $query);
            elseif ($string['query'] != '')                     $prev = '?'.$string['query'].'&p='.($curr_page - 1);
            else                                                $prev = '?p='.($curr_page - 1);;
            
            if ((!$param) || ($param == 'adm')) $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">&larr;</a> ";
            else                                $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">Предыдущая</a> ";
        }
        
        if ($curr_page < $num_page) {
            if (preg_match('/\?p\=[0-9]{1,3}/', $query))        $next = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page + 1), $query);
            elseif (preg_match('/\&p\=[0-9]{1,3}/', $query))    $next = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page + 1), $query);
            elseif ($string['query'] != '')                     $next = '?'.$string['query'].'&p='.($curr_page + 1);
            else                                                $next = '?p='.($curr_page + 1);;
            
            if ((!$param) || ($param == 'adm')) $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">&rarr;</a> ";
            else                                $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">Следующая</a> ";
        }
        
        $table->addValueArray(array(
                                    "NUM"   => $str,
                                    "PREV"  => $prev,
                                    "NEXT"  => $next
        ));
        return $table->myReplace();
    }

    Генерирует номера страниц. Из одной CMS'ки.

    netrain, 09 Сентября 2010

    Комментарии (4)
  3. PHP / Говнокод #4207

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    function ss ($id){ // получить дату рождения по ИНН для украины
    
    $result = array();
    
        //sex
        $result['sex'] = (substr($id,8,1) % 2) ? 'M' : 'F';
    
        //birthdate
        $days = substr($id,0,5);
        $year = 1900; $day = 01; $month = 01;
        while ($days > 0)
            {
            $daysInYear = (checkdate (02, 29, $year)) ? 366 : 365;
            if ($days > $daysInYear)
                {
                $days -= $daysInYear;
                $year ++;
                }
            else{
                for ($daysInMonth = 31; !checkdate($month, $daysInMonth, $year); $daysInMonth–) ;
                if ($days > $daysInMonth)
                    {
                    $days -= $daysInMonth;
                    $month ++;
                    }
                else{
                    $day = $days;
                    $days = 0;
                    }
                }
            }
        $result['year'] = $year;
        $result['month'] = $month;
        $result['day'] = $day;
    
        return $result;
    }
    
    обходить каждый день начиная с 1900 это сила

    быстрее было бы

    $inn = '2322222222';
    $inn = substr($inn,0,5);
    $normal_date = date("d.m.Y", strtotime('01/01/1900 + ' . $inn . ' days - 1 days'));

    ggggg, 09 Сентября 2010

    Комментарии (55)
  4. PHP / Говнокод #4206

    +144

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    // Строк 50 кода
    
    
    
    <style>
    
      switch ($view_mod)
      {
    
        default :
    
          echo ('
            // Здесь для элементов разметки стили выводятся
            ');
    
        break;
    
        2 :
    
          echo ('
            // Соответственно здесь
          ');
    
        break;
    
        3 :
    
          echo ('
            // И здесь
          ');
    
        break;
    
      }
    
    </style>
    
    
    
    // Еще строк 250 кода
    
    
    
    if (!isset ($color_theme)) then
    {
      $color_theme=$def_color_theme;
    }

    В универе учат в основном Delphi, решил, что надо самостоятельно хорошо изучить что-нить еще. Решил попробовать PHP и непривычно постоянно с одного языка на другой перескакивать. Блин, eб@нулся, пока нашел ошибки on lines: 18, 26 и 44...

    RESIN, 09 Сентября 2010

    Комментарии (8)
  5. PHP / Говнокод #4202

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    <?php
    class WikiParser{
    private $p;
    function __construct($p){
    $this->p=$p;
    }
    function parse(){
    $this->p = preg_replace('/\[\[([^\/"?[=|]+?)\]\]/siu', '<a href="link.php?sea=$1">$1</a>', $this->p);
    $this->p = preg_replace('/\[\[([^\/"?[=|]+?)\|(.+?)\]\]/siu', '<a href="link.php?sea=$1">$2</a>', $this->p);
    $this->p = preg_replace('/\[\[([a-z]+?:\/\/[^"|]*?)\|([^"?[=|]+?)\]\]/siu', '<a href="$1">$2</a>', $this->p);
    $this->p = preg_replace('/\[\[([a-z]+?:\/\/[^"|]*?)\]\]/siu', '<a href="$1">$1</a>', $this->p);
    
    $this->p = preg_replace('/&lt;&lt;([^\/"?[=|]+?)&gt;&gt;/siu', '<a href="link.php?sea=$1">$1</a>', $this->p);
    $this->p = preg_replace('/&lt;&lt;([^\/"?[=|]+?)\|(.+?)&gt;&gt;/siu', '<a href="link.php?sea=$1">$2</a>', $this->p);
    $this->p = preg_replace('/&lt;&lt;([a-z]+?:\/\/[^"|]*?)\|([^"?[=|]+?)&gt;&gt;/siu', '<a href="$1">$2</a>', $this->p);
    $this->p = preg_replace('/&lt;&lt;([a-z]+?:\/\/[^"|]*?)&gt;&gt;/siu', '<a href="$1">$1</a>', $this->p);
    $this->p = preg_replace('/\*\*\*?([^"?=#%]+?)\*\*\*?/siu', '<b>$1</b>', $this->p);
    $this->p = preg_replace('/\-\-\-?([^"?=#%]+?)\-\-\-?/siu', '<s>$1</s>', $this->p);
    $this->p = preg_replace('/\/\/\/?([^"?=#%]+?)\/\/\/?/siu', '<i>$1</i>', $this->p);
    $this->p = preg_replace('/\r?\n\r?\n/', '</p><p>', $this->p);
    $this->p = preg_replace('/\n/', '<br/>', $this->p);
    $this->p = preg_replace('/\{\{locked\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Статья огорожена от <a href="link.php?sea=вапераст">ваперастов</a></td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{locked\|(.*?)\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Статья огорожена от $1</td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{недопись\}\}/siu', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle"><b>Недопись</b><br>Ваша статья - Гавно. Короткая, тупая и малоинформативная</td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{недопись\|([^|]*?)\}\}/siu', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Недопись<br>Ваша статья - $1</td></tr></table>', $this->p);
    $this->p = preg_replace('/\{\{moved\|(.*?)\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle"><b>Статья перемещена</b><br>--&gt;$1</td></tr></table>', $this->p);
    $this->p = preg_replace('/[[<]#[]>]/', '', $this->p);
    if(!preg_match('#^<p>.*</p>$#siu', $this->p)) $this->p='<p>'.$this->p.'</p>';
    $this->p = preg_replace('/<p><\/p>/siu', '', $this->p);   
    }
    function get(){return $this->p;}
    }
    ?>

    Без комментариев

    startapp, 08 Сентября 2010

    Комментарии (40)
  6. PHP / Говнокод #4201

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    function renameimage($dir,$file) 
      {
         $words=array('fuck','blia','fuck_you_spilberg','mazfaka','simpsons');
         $rand=array_rand($words);
         $type_foto=end(explode(".", $file));
         $new_name_of_foto=md5($rand[$words].$file).'.'.$type_foto;
         $ren=rename($dir.$file,$dir.$new_name_of_foto);
        if($ren)
        {
    	    return $new_name_of_foto;
        }
        else  
        {
    	    echo 'не получилось...<br>';
        }
      }

    пыщ-пыщ

    GoodTalkBot, 08 Сентября 2010

    Комментарии (3)
  7. PHP / Говнокод #4199

    +150

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    <?php
    
    function DaysDiff($d1,$d2){
    	$d2=1+strtotime($d2);
    	$d1=1+strtotime($d1);
    	
    	return floor(($d2-$d1)/86400);
    }
    
    ?>
    
    а надо бы:
    
    <?php
    
    function DaysDiff($d1,$d2){
    	return bcdiv(strtotime($d2)-strtotime($d1),86400);
    }
    
    ?>

    ferry-very-good, 08 Сентября 2010

    Комментарии (48)
  8. PHP / Говнокод #4198

    +160

    1. 1
    2. 2
    3. 3
    <?php
    
    if (preg_match("/\.[gjpi][ipnc][fgo]/i", $_SERVER['REQUEST_URI'])) exit;

    user654321, 08 Сентября 2010

    Комментарии (10)
  9. PHP / Говнокод #4195

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    $__=array('!','й','у','х',' ','е','б','е','т',' ','о','т','э',' ',',','т','е','Н');
    $_=array_reverse($__);
    $__=array_slice($_, 0, count($__)-1);
    echo implode($__);

    От автора инновационного вики-движка.
    Оригинальный посыл на PHP.
    Два массива, многозначительная третья строка.
    И все это ради задачи вывести на экран посыл на три буквы, если каждый элемент массива - буква и нулевой элемент - конец фразы.

    7ion, 08 Сентября 2010

    Комментарии (12)
  10. PHP / Говнокод #4194

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    $rows=$this->DB->FetchArray($query, MYSQL_ASSOC);
    @reset($rows);
     while (list($key, $val)=@each($rows))
    $this->$key=$val;

    Ы

    ReallyBugMeNot, 08 Сентября 2010

    Комментарии (12)