- 1
$darr = array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+173
$darr = array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
Похапе. Нафик нужны встроенные функции даты / времени? В феврале 28 дней, и баста.
Фрагмент из давно работающего проекта.
+162
<a href="/otherss/foto/">Фото</a><br>
<!-- *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= -->
<?
$ip=$REMOTE_ADDR;
$modip=substr($ip,0,7);
if ($modip=="192.168")
{
echo "<a href=\"http://192.168.1.1:8000/\">Радио</a><hr>";
// echo "<a>Радио</a><br>";
}
else
{
echo "<a href=\"http://92.255.xxx.10:8000/\">Радио</a><hr>";
// echo "<a>Радио</a><br>";
}
if ($modip=="192.168")
{
echo "<a href=\"http://192.168.1.1:3000/\">Вэб-Почта</a><br>";
}
else
{
echo "<a href=\"http://92.255.xxx.10:3000/\">Вэб-Почта</a><br>";
}
?>
<a href="/filesearch/index.php">Поиск</a><br>
<a href="http://192.168.1.1/stat/kabinet">Кабинет…</a><br>
<a href="/phone_book/">Телефон</a><a href="/phone_book/index_all.php">ы</a><br>
<br>
снова один из отжигов)
маска xxx в третьем бите ип моя, чтоб не палить)
+151
function datRus ($dat)
{ $day = substr($dat, 8, 2);
$mon = substr($dat, 5, 2);
$year= substr($dat, 0, 4);
switch ($mon)
{ case 1: $month='Января'; break;
case 2: $month='Февраля'; break;
case 3: $month='Марта'; break;
case 4: $month='Апреля'; break;
case 5: $month='Мая'; break;
case 6: $month='Июня'; break;
case 7: $month='Июля'; break;
case 8: $month='Августа'; break;
case 9: $month='Сентября'; break;
case 10: $month='Октября'; break;
case 11: $month='Ноября'; break;
case 12: $month='Декабря'; break;
default: $month=$mon; break;
}
$str = $day.' '.$month.' '.$year;
return $str;
}
Преобразование даты из mysql формата :)
+161
class Kohana_Date {
// ....
/**
* Number of hours in a day. Typically used as a shortcut for generating a
* list that can be used in a form.
*
* $hours = Date::hours(); // 01, 02, 03, ..., 10, 11, 12
*
* @param integer amount to increment each step by
* @param boolean use 24-hour time
* @param integer the hour to start at
* @return array A mirrored (foo => foo) array from start-12 or start-23.
*/
public static function hours($step = 1, $long = FALSE, $start = NULL)
{
// ... implementation
}
/**
* Number of months in a year. Typically used as a shortcut for generating
* a list that can be used in a form.
*
* Date::months(); // 01, 02, 03, ..., 10, 11, 12
*
* @uses Date::hours
* @return array A mirrored (foo => foo) array from 1-12.
*/
public static function months()
{
return Date::hours();
}
}
Занятный способ сократить код, правда вносящий небольшую суматоху )
+167
/*
`id` int(10) NOT NULL auto_increment,
`time_s` timestamp NOT NULL default CURRENT_TIMESTAMP,
`event` varchar(10) NOT NULL,
`member` int(4) NOT NULL,
PRIMARY KEY (`id`)
*/
$min = 0;
$result=mysql_query('select * from `stat_prohod`.`events`');
while ( $row = mysql_fetch_assoc ( $result ) ) {
if ($row ["id"] > $min) {
$last = $row;
$min = $row ["id"];
}
}
выборка последней записи.
табла заполняется
$query1="INSERT INTO `stat_prohod`.`events` (`event` ,`member` )VALUES ('".$action."', '".$id."');";
+152
private function http_post($url, $post_string) {
// add any additional curl options here
$options = array(CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post_string,
CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0");
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$this->last_response = $response;
$info = curl_getinfo($ch);
curl_close($ch);
// all good
if ($info['http_code'] == 204)
return true;
return false;
}
http_post ):
+168
<?php
$date=date(("Y|m|d h:i:s"),mktime(date("h"), date("i"), date("s"), date("d"), date("m"), date("Y")));
?>
+148
<?php
require_once 'session.php';
$site = 'ns28.ath.cx';
if (isset($_SERVER['HTTPS']))
{
header('Location: http://'.$site);
exit;
}
if (!$_SESSION['logged_in'])
{
?>
<script src="http://loginza.ru/js/widget.js" type="text/javascript"></script>
<p align="center"><a href="https://loginza.ru/api/widget?token_url=https://<?=$site?>/login.php" class="loginza">Войти на этот сайт через OpenID</a></p>
<?
}
else
{
?>
<p align="center">Привет <?=$_SESSION['user']?>, вы вошли при помощи аккаунта <?=$_SESSION['from']?>!</p>
<p align="center"><a href="login.php?exit">Выйти</a> »</p>
<?
}
?>
+165
function nl() {return "\n";}
function sp() {return chr(0);}
function space() {return chr(32);}
function byte($n) {return chr($n);}
+165
<? echo "20".date('y-m-d');?>
модно выводим даты