- 1
- 2
- 3
- 4
- 5
- 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;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+159
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 автор даже не догадывается
+195
for($j=0;$j<23000000;$j++); //пауза ~3 сек
Ну как вам? :)
+154
<?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! Говно за собой не сразу увидел,
но когда "пришло озарение" было смешно.
+43
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х гиг. хнык хнык
(пока правдо не надо но я попутно свою файлопомойку хочу личную)
+165
if(strpos($email,'@')===FALSE)die('error');
if(strpos($email,'.')===FALSE)die('error');
if(strlen($email)<7)die('error');
Четкая проверка почты. Регулярки зря придумывали :)
+161
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);
}
+170
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?
+163
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;
}
+160
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_;
волшебные мунипуляции
+166
$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']);
Конвертируем переносы строк типа.