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

    +50

    1. 1
    2. 2
    $result = ( !empty($this->skins[$skin]['gplum']) ) ? TRUE : FALSE;
    return $result;

    Наверное, это уже баян.

    nbspjr, 21 Ноября 2012

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

    +42

    1. 1
    2. 2
    if( !empty($data['date']) )
          $data['date'] = preg_replace("/(\d+)\.(\d+)\.(\d+)/", "$3.$2.$1", $data['date']);

    nicksevenfold, 21 Ноября 2012

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

    +37

    1. 1
    2. 2
    if (isset($_GET['oneway']))
                $_SESSION['oneway'] = intval($_GET['oneway']) == 1 ? 1 : 0;

    Уточню : надо именно int, а не bool для API сервиса.
    На ум приходят 2 других более красивых способа нормализации. Может и ещё что-то есть.

    kryoz, 21 Ноября 2012

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

    +46

    1. 1
    for($i=0;$i<=100;$i++)echo(!$i?$i:($i%3==0&&$i%5==0?'FizzBuzz':($i%3==0?'Fizz':($i%5==0?'Buzz':$i)))).'<br>';

    FizzBuzz - мое решение.

    pkot, 20 Ноября 2012

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

    +46

    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
    public function custom_result_object($class_name)
    	{
    		if (array_key_exists($class_name, $this->custom_result_object))
    		{
    			return $this->custom_result_object[$class_name];
    		}
    
    		if ($this->result_id === FALSE OR $this->num_rows() == 0)
    		{
    			return array();
    		}
    
    		// add the data to the object
    		$this->_data_seek(0);
    		$result_object = array();
    
    		while ($row = $this->_fetch_object())
    		{
    			$object = new $class_name();
    
    			foreach ($row as $key => $value)
    			{
    				$object->$key = $value;
    			}
    
    			$result_object[] = $object;
    		}
    
    		// return the array
    		return $this->custom_result_object[$class_name] = $result_object;
    	}
    
    	// --------------------------------------------------------------------
    
    	/**
    	 * Query result.  "object" version.
    	 *
    	 * @access	public
    	 * @return	object
    	 */
    	public function result_object()
    	{
    		if (count($this->result_object) > 0)
    		{
    			return $this->result_object;
    		}
    
    		// In the event that query caching is on the result_id variable
    		// will return FALSE since there isn't a valid SQL resource so
    		// we'll simply return an empty array.
    		if ($this->result_id === FALSE OR $this->num_rows() == 0)
    		{
    			return array();
    		}
    
    		$this->_data_seek(0);
    		while ($row = $this->_fetch_object())
    		{
    			$this->result_object[] = $row;
    		}
    
    		return $this->result_object;
    	}

    Govnisti_Diavol, 17 Ноября 2012

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

    +39

    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
    <?php
    session_start();
    include ("system/db.config.php");
         if (empty($_SESSION['login']) or empty($_SESSION['id']))
               {
                  header("Location: index.php");
               }
               else
              {
                 //Выясняем, кто зашел сюда, если админ, удаляем юзера, если нет - перекидываем в список пользователей
                 $fResult = mysql_query("SELECT user_level FROM users WHERE id=".$_SESSION['id'], $db);
                 $fRow = mysql_fetch_array($fResult);
                 if($fRow['user_level'] == 1)
                 {
                     $DelTenderId = $_GET['id'];
                     $DellFiled = mysql_query("SELECT file_link FROM tenders WHERE id=".$DelTenderId);
                     $isdLnk = mysql_fetch_array($DellFiled);
                     $delPater = "uploads/".$isdLnk['file_link'];
                     unlink($delPater);
                     mysql_query("DELETE FROM tenders WHERE id =".$DelTenderId);
                     header("Location: tenders_list.php"); 
                 }
                 else
                 {
                   header("Location: home.php"); 
                 }
             }
    ?>

    Ну как то так....

    Govnisti_Diavol, 17 Ноября 2012

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

    +141

    1. 1
    C:\>php -r "echo mb_convert_encoding('хуй', 'cp866', 'windows-1251') . chr(7);"

    __proto__, 15 Ноября 2012

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

    +43

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if(!empty($_POST['word'])) {
    	$sql = "SELECT `sysname` FROM `__" . $this->tables[0] . "` WHERE `title`='".$_POST['word']."'";
    	$model = $conn->fetchAll($sql);
    	if(!sizeof($model)) {
    		header("Location: " . $_SERVER['HTTP_REFERER']);
    		exit;
    	}
    	header("Location: /catalog/brands/" . $model[0]['sysname'] . ".html");
    	exit;
    }

    Маленький кусок проекта на Symfony 2.

    UnnamedUser, 14 Ноября 2012

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

    +54

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $postitle = str_replace (' ', '-', $title);
    				$postitle = str_replace ('/', '', $postitle);
    				$postitle = str_replace ('\\', '', $postitle);
    				$postitle = str_replace (':', '', $postitle);
    				$postitle = str_replace ('<', '', $postitle);
    				$postitle = str_replace ('>', '', $postitle);
    				$postitle = str_replace ('*', '', $postitle);
    				$postitle = str_replace ('?', '', $postitle);
    				$postitle = str_replace ('|', '', $postitle);
    				$postitle = str_replace ('"', '', $postitle);
    				$postitle = preg_replace ('#\[.*?\]#isu', '', $postitle);

    aleksey, 14 Ноября 2012

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

    +44

    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 db_connect($serverMySql, $db_log, $db_pass) //create connection
    {
        $r = mysql_connect($serverMySql, $db_log, $db_pass);
        return $r;
    }
    //....
    // страницы
    if (empty($_GET["p"])) {
        $_GET["p"] = "1";
    }
    $p = $_GET["p"];
    
    // защита от ввода  
    if (preg_match("/[%a-z_@.,^=:;Р°-СЏ\"*()&$#в„–+\-!?<>\~`|[{}\]]/i", $p)) {
        die(header("Location:sluch_list.php"));
    }

    http://hashcode.ru/questions/163555/php-%D0%B2%D1%8B%D0%B2%D0%BE%D0%B4-%D1%84%D1%80%D0%B0%D0%B7-%D0%BF%D0%BE-%D1%80%D0%B5%D0%B9%D1%82%D0%B8%D0%BD%D0% B3%D1%83

    nolka4, 14 Ноября 2012

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