- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
function decode_php_abbr($abbr){
if(strpos($abbr,'PHP')!==false){
$abbr=str_replace('PHP','PHP: Hypertext Preprocessor',$abbr);
decode_php_abbr($abbr);
}
else echo $abbr;
}
decode_php_abbr('PHP');
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+159
function decode_php_abbr($abbr){
if(strpos($abbr,'PHP')!==false){
$abbr=str_replace('PHP','PHP: Hypertext Preprocessor',$abbr);
decode_php_abbr($abbr);
}
else echo $abbr;
}
decode_php_abbr('PHP');
Расшифровываем аббревиатуру PHP или когда на работе немного скучно.
+166
define("DB_YESTERDAY",date('d/m/Y', time()-172800-86400-86400-86400
-86400-86400-86400-86400-86400-86400-86400-86400-86400-86400-86400
-86400-86400-86400-86400-86400-86400-86400-86400-86400-86400)); //если более 2 дней подряд были выходные, валюты не показывались. Дописано "-86400"
Дописано -86400? Забыли упомянуть, что 24 раза(
+158
/*...тут много строк...*/
if($arraySection[$section_id[$j]]=='0'){
echo '';
}
else{
echo '
<li><a href="/'.$arraySection[$section_id[$j]].'">'.$arraySection[$section_id[$j]].'</a></li>
';}
/*...тут много строк...*/
Любитель else
+161
if (($arrRoleInHold = $this->syncByToken($token)) && (!$arrRoleInHold)) {
throw new Exception('');
}
хорошее условие!
+162
class StupidClass
{
public function __toString()
{
return 'this';
}
public function hax()
{
return $this === $$$$$$this;
}
}
var_dump((new StupidClass)->hax()); // true
Уииии
+155
<?php
function load ($file) {
static $files = null;
$files or $files = [];
if (!isset($files[$file])) {
require($file);
$files[$file] = true;
}
}
$times = 1000000;
$time1 = microtime(true);
for ($i = 0; $i < $times; $i ++) {
require_once('inc.php');
}
$end1 = microtime(true) - $time1;
$time2 = microtime(true);
for ($i = 0; $i < $times; $i ++) {
load('inc.php');
}
$end2 = microtime(true) - $time2;
echo "require_once = $end1 vs \nload = $end2";
Вот это да... require_once работает в ~8 раз медленнее чем функция load. Вывод:
require_once = 16.962311029434 vs
load = 2.6861710548401
Содежания файла inc.php:
<?php echo 'Hello, world!';
+151
$friends = mysql_query("(SELECT * FROM `friends` WHERE `from` LIKE '{$act}' AND `to` LIKE '{$act}' AND `isaccepted` = '1') UNION (SELECT `id` , `name` , `surname` FROM `users_info`);");
$friend = array();$loop=0;
while($fetch = mysql_fetch_assoc($friends)) {
if ($fetch['from'] == $act) $search=$fetch['to']; else $search=$fetch['from'];
$friend[$loop]=mysql_fetch_assoc(mysql_query("SELECT `id`,`name`,`surname` FROM `users_info` where `id`='{$search}'"));
$loop++;
}
Почему не работает?
+156
$query = "INSERT INTO news (title, img_url, subtitle, content, date, time, id)
VALUES (\"" .
$_POST["title"] . "\", \"" .
$_POST["img_url"] . "\", \"" .
$_POST["subtitle"] . "\", \"" .
$_POST["content"] . "\", \"" .
date("Y-m-d") . "\", \"" .
time() . "\", " .
DEFAULT . ");";
только начал php. уверень, есть решение поэлегантнее этого
+159
if((!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/") && !$_SESSION['user']) {$smarty->display(dirname(__FILE__).'/system/template/index.html'); exit;}
if ($_SESSION['user']['login'] && (!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/")) {require './system/modules/info/main.php';$smarty->assign('c',$_SESSION['user']); $smarty->display(dirname(__FILE__).'/system/template/home/index.html');}
if((!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/") && !$_SESSION['user']) {$smarty->display(dirname(__FILE__).'/system/template/home/guest.html');}
Вот как строится новая соцсеть
+158
if((!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/") && !$_SESSION['user']) {echo "index";}