- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
public function responsive()
{
$month = array("1" => "Responsive", "2" => "Unresponsive");
for ($i = 1; $i <= 2; $i++)
{
$data[] = array('text' => $month[$i], 'value' => $i);
}
echo json_encode($data);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+150
public function responsive()
{
$month = array("1" => "Responsive", "2" => "Unresponsive");
for ($i = 1; $i <= 2; $i++)
{
$data[] = array('text' => $month[$i], 'value' => $i);
}
echo json_encode($data);
}
Мне кажеться индусы пишут лучше
+152
<?php
//Скрипт рассчета времени.
if (!empty($_POST["from_hours"])) { $from_hours = $_POST["from_hours"]; } else { unset($_POST["from_hours"]); }
if (!empty($_POST["from_minutes"])) { $from_minutes = $_POST["from_minutes"]; } else { unset($_POST["from_minutes"]); }
if (!empty($_POST["from_seconds"])) { $from_seconds = $_POST["from_seconds"]; } else { unset($_POST["from_seconds"]); }
if (!empty($_POST["from_month"])) { $from_month = $_POST["from_month"]; } else { unset($_POST["from_month"]); }
if (!empty($_POST["from_day"])) { $from_day = $_POST["from_day"]; } else { unset($_POST["from_day"]); }
if (!empty($_POST["from_year"])) { $from_year = $_POST["from_year"]; } else { unset($_POST["from_year"]); }
if (!empty($_POST["to_hours"])) { $to_hours = $_POST["to_hours"]; } else { unset($_POST["to_hours"]); }
if (!empty($_POST["to_minutes"])) { $to_minutes = $_POST["to_minutes"]; } else { unset($_POST["to_minutes"]); }
if (!empty($_POST["to_seconds"])) { $to_seconds = $_POST["to_seconds"]; } else { unset($_POST["to_seconds"]); }
if (!empty($_POST["to_month"])) { $to_month = $_POST["to_month"]; } else { unset($_POST["to_month"]); }
if (!empty($_POST["to_day"])) { $to_day = $_POST["to_day"]; } else { unset($_POST["to_day"]); }
if (!empty($_POST["to_year"])) { $to_year = $_POST["to_year"]; } else { unset($_POST["to_year"]); }
$time = mktime($to_hours,$to_minutes,$to_seconds,$to_month,$to_day,$to_year) - mktime($from_hours,$from_minutes,$from_seconds,$from_month,$from_day,$from_year);
if (!empty($time)) {
echo
"От $from_month/$from_day/$from_year $from_hours:$from_minutes:$from_seconds
<br>До $to_month/$to_day/$to_year $to_hours:$to_minutes:$to_seconds
<br>Секунд: $time
<br>Минут: ",$time/60,"
<br>Часов: ",$time/60/60,"
<br>Дней: ",$time/60/60/24,"
<br>Недель: ",$time/60/60/24/365*12*4,"
<br>Месяцев: ",$time/60/60/24/365*12,"
<br>Лет: ",$time/60/60/24/365;
}
else {
echo "<h2>Введите данные для расчета</h2>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Сколько времени пройдет от и до</title>
</head>
<body>
<p>Сколько времени от:</p>
<form method="post" target="_blank" action="date.php">
<input type="text" name="from_year"> Год<br>
<input type="text" name="from_month"> Месяц<br>
<input type="text" name="from_day"> День<br>
<input type="text" name="from_hours"> Час<br>
<input type="text" name="from_minutes"> Минут<br>
<input type="text" name="from_seconds"> Секунд<br>
<p>Сколько времени до:</p>
<input type="text" name="to_year"> Год<br>
<input type="text" name="to_month"> Месяц<br>
<input type="text" name="to_day"> День<br>
<input type="text" name="to_hours"> Час<br>
<input type="text" name="to_minutes"> Минут<br>
<input type="text" name="to_seconds"> Секунд<br>
<input type="submit" value="Рассчитать">
</form>
<p>* Заполнять все поля не объязательно.</p>
</body>
</html>
Скрипт расчета времени от и до.
Как бы улучшить этот говнокод на php?
+123
Mage::run();
С этого места начинается боль и мучения.
+156
<?php
$dataProvider = new CActiveDataProvider('User', array(
'criteria'=>array(
'condition' => 'id = ' . $id,
),
));
$regdata = $dataProvider->getData();
if (is_array($regdata)) $regdata = current($regdata);
//....
$this->redirect(Yii::app()->createUrl('user/profile'));
Как не стоит писать на Yii
+143
<?php
function get_md5($filename){
return md5_file($filename)
}
echo "get_md5($_POST)";
?>
Только начал php, посоветуйте литературу Х)
+147
if(is_array($_REQUEST[$fieldname]))
$value = $_REQUEST[$fieldname];
else
$value = trim($_REQUEST[$fieldname]);
Если это не массив то всеравно используем его как массив.
Код с популярной CRM.
+143
Хуь.
Кто хочет глотнуть спермы?
+164
function boolConvert($value){
if(strtolower($value)=='true')
return 1;
if(strtolower($value)=='false')
return 0;
return $value;
}
+130
public static function checkUserRights($project, $user, $action, $allowView = false)
{
$action_id = Actions::getActionIdByName($action);
$user_role = ProjectsRoles::getUserRoleInProject($project, $user);
if(is_null($user_role))
HUtils::Exception(403);
$roles = Roles::getRolesOrderedByWeight();
$user_role = $user_role->role;
foreach($roles as $role)
{
if($role->weight <= $user_role)
{
$user_role -= $role->weight;
if(in_array($action_id,HUtils::Parse($role->actions)))
return 1;
}
}
if(!$allowView)
HUtils::Exception(403);
}
Функция проверки прав.
$allowView в конце функции намекает, что доступ получен не будет. Никогда. Вроде бы.
+163
require_once('bbcode.php');
$bbcode_ = $bbcode;
global $bbcode;
$bbcode = $bbcode_;
bbcode_format($text);
При этом:
function bbcode_format($str, $bbcode = false)