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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function DateFromDBToHr($date)
    {
    	$datetime = explode(" ", $date);
    	$dates = explode("-", $datetime[0]);
    	return (intval($dates[0])) ? date("d-M-Y", mktime(0, 0, 0, $dates[1], $dates[2], $dates[0])) : false;
    }

    про то, что форматировать дату можно в запросе или про существование strtotime автор даже не догадывается

    elw00d, 14 Января 2011

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

    +195

    1. 1
    for($j=0;$j<23000000;$j++); //пауза ~3 сек

    Ну как вам? :)

    Yanovsky, 13 Января 2011

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

    +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
    <?php
    require_once('MultiAutoload.php');
    
    class Dispatcher {
    
    	private $handle;
    
    	function __construct($event_handle) {
    		$this->handle = $event_handle;
    	}
    
    	function handleEvent() {
    		$name = 'Handler_'.$this->handle;
    		if (class_exists($name)) {
    			$handler_obj = new $name($this->handle);
    			$response = $handler_obj->secureHandler();
    			return $response;
    		}
    		else {
    			throw new Exception('Event handling is impossible!');
    		}
    	}
    }
    ?>

    Немного экзотики: PHP в стиле Win32! Говно за собой не сразу увидел,
    но когда "пришло озарение" было смешно.

    dwinner, 13 Января 2011

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

    +43

    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
    function ntfs_filesize($filename) 
    {
        return exec("
                for %v in (\"".$filename."\") do @echo %~zv
        ");
    }
    // LINUX SERVERS:
    // str perl_filesize( str $filename );
    /*
    DESCRIPTION: returns the filesize of a large file in string format to... 
    ... prevent 32-bit integer walls  using perl through linux command line.
    */
    function perl_filesize($filename) 
    {
        return exec("
                perl -e 'printf \"%d\n\",(stat(shift))[7];' ".$filename."
        ");
    }

    вот вам!
    http://ru.php.net/filesize отсюда.

    вообще ебанутость filesize в пхп теперь не позволит мне без костылей хранить на сайте файлы больше 2х гиг. хнык хнык
    (пока правдо не надо но я попутно свою файлопомойку хочу личную)

    brainstorm, 13 Января 2011

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

    +165

    1. 1
    2. 2
    3. 3
    if(strpos($email,'@')===FALSE)die('error');
    if(strpos($email,'.')===FALSE)die('error');
    if(strlen($email)<7)die('error');

    Четкая проверка почты. Регулярки зря придумывали :)

    assous, 13 Января 2011

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

    +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
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    function toTrash($id)
        {
            $data = array(
                'order_id'          => $id,
                'order_archived'    => 0,
                'order_trashed'     => 1,
    			'order_candelled' 	=> 0
            );
    
            return $this->update_order($data);
        }
    
        function toArchive($id)
        {
            $data = array(
                'order_id'          => $id,
                'order_archived'    => 1,
                'order_trashed'     => 0,
    			'order_candelled' 	=> 0
            );
    
            return $this->update_order($data);
        }
    
        function restore($id)
        {
            $data = array(
                'order_id'          => $id,
                'order_archived'    => 0,
                'order_trashed'     => 0
    			'order_candelled' 	=> 0
            );
    
            return $this->update_order($data);
        }
    	    
    	function cancelled($id)
    	    {
    	        $data = array(
    	            'order_id'          => $id,
    	            'order_archived'    => 0,
    	            'order_trashed'     => 0,
    				'order_candelled' 	=> 1
    	        );
    
    	        return $this->update_order($data);
    	    }

    DyX_LesA, 12 Января 2011

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

    +170

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function loger2($comment)
    {
    	$f = fopen(dirname(__FILE__).'/log2.html', 'a+');
    	fwrite($f, $comment);
    	fclose($f);
    }
    function loger($comment)
    {
    	$f = fopen(dirname(__FILE__).'/log.html', 'a+');
    	fwrite($f, $comment);
    	fclose($f);
    }

    loger100500?

    govnozmey, 12 Января 2011

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

    +163

    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
    function db_query($sql)
    {
    	global $dbcnx;
    	$k=0;
    	while(!@$res=mysql_query($sql))
    	{
    		if($k>5)
    		{
    			$f=fopen(dirname(__FILE__).'/tmp/error.log','a');
    			fwrite($f,"\n".mysql_error().' in '.$sql."\n");
    			fclose($f);
    			die();
    		}
    		//@mysql_close($dbcnx);
    		//MysqlConnect();
    		$k++;
    	}
    	return $res;
    }

    govnozmey, 12 Января 2011

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

    +160

    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
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    function sinonimizer($my_text)
    {
    $arr_ = file(dirname(__FILE__).'/new_words.txt');
    $arr = array();
    foreach ($arr_ as $str)
    {
        $str = trim($str);
    	$t1 = explode('|', $str);
    	$master = trim($t1[0]); //пихаем слово которое заменять
    	if (!isset($t1[1]))
    		continue;
    	$t2 = explode('|', $t1[1]); //Тут слово которым заменять
    	if (sizeof($t2) == 0)
    		continue;
    	//Дальше волшебные мунипуляции
    
    	foreach ($t2 as $t)
    		$arr[crc32(strtolower($master))][crc32(strtolower(trim($t)))] = array('word' =>
    		trim($t), 'rep' => 0);
    }
    $my_text=str_replace(array("\n","\t","\r")," ",$my_text);
    $text_arr = explode(' ', $my_text);
    $str_ = '';
    
    foreach ($text_arr as $item)
    {
    	$fl = false;
    	$t = str_replace('.', '', str_replace(',', '', str_replace('!', '',
    	str_replace('?', '', str_replace('"', '', str_replace('\'', '',
    	str_replace('<', '', str_replace('>', '', str_replace(':', '',
    	str_replace(';', '', $item))))))))));
    	if (isset($arr[crc32(strtolower($t))]))
    	{
    		foreach ($arr[crc32(strtolower($t))] as $k => $v)
        		if ($v['rep'] == 0)
    			{
    				$str_ .= str_ireplace($t, "$v[word]", $item) . ' ';
    				$$v['rep'] = 1;
    				$fl = true;
    				break;
    			}
    	}
    	if (!$fl) $str_ .= $item . ' ';
    }
    
    return $str_;
    }
    
    function sinonimizer_new($my_text)
    {
    $arr_ = file(dirname(__FILE__).'/new_words.txt');
    $arr = array();
    foreach ($arr_ as $str)
    {
        $str = trim($str);
    	$t1 = explode('|', $str);
    	$master = trim($t1[0]); //пихаем слово которое заменять
    	if (!isset($t1[1]))
    		continue;
    	$t2 = explode('|', $t1[1]); //Тут слово которым заменять
    	if (sizeof($t2) == 0)
    		continue;
    	//Дальше волшебные мунипуляции
    
    	foreach ($t2 as $t)
    		$arr[(strtolower($master))][(strtolower(trim($t)))] = array('word' =>
    		trim($t), 'rep' => 0);
    }
    $my_text=str_replace(array("\n","\t","\r")," ",$my_text);
    $text_arr = explode(' ', $my_text);
    
    $str_ = '';
    
    foreach ($text_arr as $item)
    {
    	$fl = false;
    	$t = str_replace('.', '', str_replace(',', '', str_replace('!', '',
    	str_replace('?', '', str_replace('"', '', str_replace('\'', '',
    	str_replace('<', '', str_replace('>', '', str_replace(':', '',
    	str_replace(';', '', $item))))))))));
    
    	if (isset($arr[(strtolower($t))]))
    	{
           
    		foreach ($arr[(strtolower($t))] as $k => $v)
        		if ($v['rep'] == 0)
    			{
    				$str_ .= str_ireplace($t, "$v[word]", $item) . ' ';
    				$$v['rep'] = 1;
    				$fl = true;
    				break;
    			}
    	}
    	if (!$fl) $str_ .= $item . ' ';
    
    
    }
    
    return $str_;

    волшебные мунипуляции

    govnozmey, 12 Января 2011

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $res['descr'] = str_replace("\n\n\n", "<br>", $res['descr']);
    $res['descr'] = str_replace("\n\n", "<br>", $res['descr']);
    $res['descr'] = str_replace("<br><br><br>", "<br>", $res['descr']);
    $res['descr'] = str_replace("<br><br>", "<br>", $res['descr']);
    $res['descr'] = str_replace("<br><br>", "<br>", $res['descr']);

    Конвертируем переносы строк типа.

    govnozmey, 12 Января 2011

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