1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. PHP / Говнокод #4189

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $a = "1";
    $b = "$a";
    
    if($a == $b) {
    echo '$a = $b';
    }

    Восемь часов за компом.. Посмотрел на код еще раз :D

    bafoed, 07 Сентября 2010

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

    +143

    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
    // Так мы генерируем страницу:
    ob_start();
    
    renderPage($price, $order);
    
    $renderPage = ob_get_clean();
    
    // Функция renderPage выглядит так:
    function renderPage(&$setup, &$order){
    ?>
    <div id="setupMenu">
    <!-- дальше простой html с подстановкой php-переменных -->
    <?php } ?>

    Вот почему у функции нельзя было сделать простой return, а надо было закрывать скобки php и затем при вызове использовать ob_*, чтобы получить html.

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

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