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

    +152.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?php
    if(!($str===$str2)) {
    	#ибо !=== не существует (с)Денис Колисниченко - книга "Самоучитель PHP 5"
    }
    ?>

    Не покупайте эту книгу =\

    guest, 14 Января 2009

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

    +35.8

    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
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    <?php
    function utf8_to_cp1251($text) {
    	$text = str_replace(chr(208),chr(208).chr(160),$text); # Р
    	$text = str_replace(chr(192),chr(208).chr(144),$text); # А
    	$text = str_replace(chr(193),chr(208).chr(145),$text); # Б
    	$text = str_replace(chr(194),chr(208).chr(146),$text); # В
    	$text = str_replace(chr(195),chr(208).chr(147),$text); # Г
    	$text = str_replace(chr(196),chr(208).chr(148),$text); # Д
    	$text = str_replace(chr(197),chr(208).chr(149),$text); # Е
    	$text = str_replace(chr(168),chr(208).chr(129),$text); # Ё
    	$text = str_replace(chr(198),chr(208).chr(150),$text); # Ж
    	$text = str_replace(chr(199),chr(208).chr(151),$text); # З
    	$text = str_replace(chr(200),chr(208).chr(152),$text); # И
    	$text = str_replace(chr(201),chr(208).chr(153),$text); # Й
    	$text = str_replace(chr(202),chr(208).chr(154),$text); # К
    	$text = str_replace(chr(203),chr(208).chr(155),$text); # Л
    	$text = str_replace(chr(204),chr(208).chr(156),$text); # М
    	$text = str_replace(chr(205),chr(208).chr(157),$text); # Н
    	$text = str_replace(chr(206),chr(208).chr(158),$text); # О
    	$text = str_replace(chr(207),chr(208).chr(159),$text); # П
    	$text = str_replace(chr(209),chr(208).chr(161),$text); # С
    	$text = str_replace(chr(210),chr(208).chr(162),$text); # Т
    	$text = str_replace(chr(211),chr(208).chr(163),$text); # У
    	$text = str_replace(chr(212),chr(208).chr(164),$text); # Ф
    	$text = str_replace(chr(213),chr(208).chr(165),$text); # Х
    	$text = str_replace(chr(214),chr(208).chr(166),$text); # Ц
    	$text = str_replace(chr(215),chr(208).chr(167),$text); # Ч
    	$text = str_replace(chr(216),chr(208).chr(168),$text); # Ш
    	$text = str_replace(chr(217),chr(208).chr(169),$text); # Щ
    	$text = str_replace(chr(218),chr(208).chr(170),$text); # Ъ
    	$text = str_replace(chr(219),chr(208).chr(171),$text); # Ы
    	$text = str_replace(chr(220),chr(208).chr(172),$text); # Ь
    	$text = str_replace(chr(221),chr(208).chr(173),$text); # Э
    	$text = str_replace(chr(222),chr(208).chr(174),$text); # Ю
    	$text = str_replace(chr(223),chr(208).chr(175),$text); # Я
    	$text = str_replace(chr(224),chr(208).chr(176),$text); # а
    	$text = str_replace(chr(225),chr(208).chr(177),$text); # б
    	$text = str_replace(chr(226),chr(208).chr(178),$text); # в
    	$text = str_replace(chr(227),chr(208).chr(179),$text); # г
    	$text = str_replace(chr(228),chr(208).chr(180),$text); # д
    	$text = str_replace(chr(229),chr(208).chr(181),$text); # е
    	$text = str_replace(chr(184),chr(209).chr(145),$text); # ё
    	$text = str_replace(chr(230),chr(208).chr(182),$text); # ж
    	$text = str_replace(chr(231),chr(208).chr(183),$text); # з
    	$text = str_replace(chr(232),chr(208).chr(184),$text); # и
    	$text = str_replace(chr(233),chr(208).chr(185),$text); # й
    	$text = str_replace(chr(234),chr(208).chr(186),$text); # к
    	$text = str_replace(chr(235),chr(208).chr(187),$text); # л
    	$text = str_replace(chr(236),chr(208).chr(188),$text); # м
    	$text = str_replace(chr(237),chr(208).chr(189),$text); # н
    	$text = str_replace(chr(238),chr(208).chr(190),$text); # о
    	$text = str_replace(chr(239),chr(208).chr(191),$text); # п
    	$text = str_replace(chr(240),chr(209).chr(128),$text); # р
    	$text = str_replace(chr(241),chr(209).chr(129),$text); # с
    	$text = str_replace(chr(242),chr(209).chr(130),$text); # т
    	$text = str_replace(chr(243),chr(209).chr(131),$text); # у
    	$text = str_replace(chr(244),chr(209).chr(132),$text); # ф
    	$text = str_replace(chr(245),chr(209).chr(133),$text); # х
    	$text = str_replace(chr(246),chr(209).chr(134),$text); # ц
    	$text = str_replace(chr(247),chr(209).chr(135),$text); # ч
    	$text = str_replace(chr(248),chr(209).chr(136),$text); # ш
    	$text = str_replace(chr(249),chr(209).chr(137),$text); # щ
    	$text = str_replace(chr(250),chr(209).chr(138),$text); # ъ
    	$text = str_replace(chr(251),chr(209).chr(139),$text); # ы
    	$text = str_replace(chr(252),chr(209).chr(140),$text); # ь
    	$text = str_replace(chr(253),chr(209).chr(141),$text); # э
    	$text = str_replace(chr(254),chr(209).chr(142),$text); # ю
    	$text = str_replace(chr(255),chr(209).chr(143),$text); # я
    	return $text;
    }
    ?>

    Функция переобразования кодировки

    guest, 14 Января 2009

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

    +51.5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $screen_width = "<script language=\"javascript\">document.write(screen.width);</script>";
    
    if ($screen_width < 400){
             $new_limit = "900";
             $limit_var = "width";
     }elseif ($screen_width > 400){
             $new_limit = "400";
             $limit_var = "width";
          }else {
                          $new_limit = $image_info[0];
             $limit_var = "width";
          }

    Ресайз картинко по ширине экрана %)

    guest, 14 Января 2009

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

    +16

    1. 1
    /* а в этих ваших пхп и джаваскрипт есть ==== и !=== ? */

    guest, 14 Января 2009

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

    +24

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <? if ($mode=="structure") echo
    "<td class=\"under_hdr1\" align=\"center\">СТРУКТУРА БИБЛИОТЕКИ
    <p>Руководство</p>
    <table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"5\" class=\"gude_structure\">
    <td>Директор<td>
    <tr>
    <td><td>Кондрашова Валентина Георгиевна<br>конт.тел.:<br>адрес: ул. Московская 2 \"А\", комн. 424<br>Время работы: 09:00-18:00
    </table>
    <p>
    <table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"5\" class=\"gude_structure\">

    Дальше огромная куча текста в таком стиле

    guest, 13 Января 2009

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

    +36.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $attachItems = "<table style=\'font-size : 8pt\' cellspacing = \'0\'><tr>"
    ."<td><img src=\'/js/extjs/resources/images/talentor/ico/files/mov.gif\'>  </td>"
    ."<td>".($justHTML == false ? '<a href=\\\'#\\\''
    .' onclick=\"new Ext.Window({title:\\\''.$rowData['name'].'\\\',resizable:false,maximizable:true,cls:\\\'window\\\',modal: true,width: 417,height : 375     ,html:\\\''.htmlspecialchars(flv('/files/persons/'.$rowData['name'],400,300)).'\\\'}).show();\"'
    ."\'>".$rowData['name']."</a>" : $rowData['name'] )."</td>"
    .(($justHTML == false && $deleteAttach == true) ? "<td>  <img  onclick=\'ERP.INTERVIEW.deleteVideo(\\\"".$rowData['name']."\\\",document.getElementById(\\\"intvideoid\\\").value,".$intId.",".$personId.")\' onmouseover=\' this.src=\\\"/js/extjs/resources/images/talentor/ico/remove_active.gif\\\" \' onmouseout=\'this.src=\\\"/js/extjs/resources/images/talentor/ico/remove.gif\\\" \' src=\'/js/extjs/resources/images/talentor/ico/remove.gif\'></td>" : '')
    ."</tr></table>"
    ."<input type=\'hidden\' id=\'intvideoid\' value=\'".$rowData['id']."\'>";
    if  (!$justHTML && $deleteAttach) $attachItems = "{xtype: 'panel', id: 'intVideo', html: '".$attachItems."'}";

    Нет слов

    guest, 13 Января 2009

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

    +30.6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function dehtml($string) {
        $string = str_replace("&", "&amp;", $string);
        $string = str_replace("\"", "`", $string);
        $string = str_replace("'", "`", $string);
        $string = str_replace("<", "&lt;", $string);
                
        return $string;
    }

    собственно, автор данной функции не подазревает о том что str_replace умеет принимать массив значений, уже не говоря о наличии htmlspecialchars и других

    guest, 13 Января 2009

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

    +32.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // -------------------------------------------
    // Возвращает все три переменные, склеенные в строку,
    // при условии что $value не пусто, иначе "".
    
    function safe_ins($before,$value,$after="") {
      if (!empty($value)) return("$before$value$after");
      else return("");
    }

    Мега способ конкатенации строк.

    guest, 12 Января 2009

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

    +29.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    ....
    // -------------------------------------------
    // Возвращает переменную $value, если она не пуста, иначе $default или false
    
    function def_inю.s($value,$default="") {
      if ($value) return("$value");
      else if ($default) return("$default");
      else return(false);
    }
    ....

    Спрашивается:
    1. для кого существует php-функция empty()?
    2. кто научил ТАК возвращать строки?

    Вот такие у нас фрилансеры...

    guest, 12 Января 2009

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

    +40.1

    1. 1
    2. 2
    $database->setQuery("SELECT DATE_FORMAT('{$date}', '%m/%d/%Y %H:%i')");
    $date = $database->loadResult();

    Джедайский подход для форматирования даты

    guest, 12 Января 2009

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