2008
12月
16

三段PHP代码
无聊时候写的三段PHP代码,纯粹是写着玩的。
日历:查看效果
随机色彩:查看效果
色彩列表:查看效果
日历:查看效果
<style>
body {
font: 12px Verdana, Arial, Helvetica, sans-serif;
}
.cal {
width: 196px;
}
.cal_title, .cal_t {
padding: 2px;
padding-top: 4px;
padding-bottom: 4px;
margin: 1px;
border: 1px solid #ddd;
text-align: center;
}
.cal_title {
font-size: 1.2em;
}
.cal_t {
width: 20px;
float: left;
}
.cal_w {
font-weight: bold;
}
.cal_wd {
background: #f2f2f2;
}
.cal_td {
background: #fec;
}
.cal_x {
color: #ddd;
}
.cal_b {
text-align: center;
width: 187px;
position: absolute;
z-index: -100;
color: #dadada;
font-weight: bold;
padding: 5px;
}
.cal_y {
font-size: 2em;
padding-top: 24px;
}
.cal_m {
padding-top: 38px;
font-size: 7em;
}
</style>
<?php
$m=date('n');
$y=date('Y');
$t=mktime(0,0,0,$m,1,$y);
$x=date('t', ($t-86400));
$f=date('w', $t)-1;
echo '<div class="cal_y cal_b">'.$y.'</div><div class="cal_m cal_b">'.$m.'</div><div class="cal"><div class="cal_t cal_w cal_wd">S</div><div class="cal_t cal_w">M</div><div class="cal_t cal_w">T</div><div class="cal_t cal_w">W</div><div class="cal_t cal_w">T</div><div class="cal_t cal_w">F</div><div class="cal_t cal_w cal_wd">S</div>';
for($i=0;$i<date('t',$t)+$f+1;$i++)echo '<div class="cal_t cal_d'.((($i-$f)==intval(date('d')) && $m==date('n') && $y==date('Y'))?' cal_td':'').(($i%7==0 || $i%7==6)?' cal_wd':'').($i>$f?'':' cal_x').'">'.($i>$f?($i-$f):($x+$i-$f)).'</div>';
if($i%7>0){
for($j=0;$j<(7-$i%7);$j++)echo '<div class="cal_t cal_d cal_x">'.($j+1).'</div>';
}
echo '</div>';
?>
body {
font: 12px Verdana, Arial, Helvetica, sans-serif;
}
.cal {
width: 196px;
}
.cal_title, .cal_t {
padding: 2px;
padding-top: 4px;
padding-bottom: 4px;
margin: 1px;
border: 1px solid #ddd;
text-align: center;
}
.cal_title {
font-size: 1.2em;
}
.cal_t {
width: 20px;
float: left;
}
.cal_w {
font-weight: bold;
}
.cal_wd {
background: #f2f2f2;
}
.cal_td {
background: #fec;
}
.cal_x {
color: #ddd;
}
.cal_b {
text-align: center;
width: 187px;
position: absolute;
z-index: -100;
color: #dadada;
font-weight: bold;
padding: 5px;
}
.cal_y {
font-size: 2em;
padding-top: 24px;
}
.cal_m {
padding-top: 38px;
font-size: 7em;
}
</style>
<?php
$m=date('n');
$y=date('Y');
$t=mktime(0,0,0,$m,1,$y);
$x=date('t', ($t-86400));
$f=date('w', $t)-1;
echo '<div class="cal_y cal_b">'.$y.'</div><div class="cal_m cal_b">'.$m.'</div><div class="cal"><div class="cal_t cal_w cal_wd">S</div><div class="cal_t cal_w">M</div><div class="cal_t cal_w">T</div><div class="cal_t cal_w">W</div><div class="cal_t cal_w">T</div><div class="cal_t cal_w">F</div><div class="cal_t cal_w cal_wd">S</div>';
for($i=0;$i<date('t',$t)+$f+1;$i++)echo '<div class="cal_t cal_d'.((($i-$f)==intval(date('d')) && $m==date('n') && $y==date('Y'))?' cal_td':'').(($i%7==0 || $i%7==6)?' cal_wd':'').($i>$f?'':' cal_x').'">'.($i>$f?($i-$f):($x+$i-$f)).'</div>';
if($i%7>0){
for($j=0;$j<(7-$i%7);$j++)echo '<div class="cal_t cal_d cal_x">'.($j+1).'</div>';
}
echo '</div>';
?>
随机色彩:查看效果
<style>
.co_div {
width: 20px;
height: 20px;
float: left;
margin-right: 1px;
margin-top: 1px;
}
</style>
<?php
function a($r, $a){
foreach($r as $k=>$v)$n[$k]=$v+(255-$v)*$a/100;
return sprintf('#%02X%02X%02X', $n[0], $n[1], $n[2]);
}
$m=150;
$a[]=rand($m,255);
$a[]=rand($m,255);
$a[]=rand($m,255);
if(min($a)>240)$a[rand(0,2)]=rand($m, 240);
for($i=0;$i<2000;$i++){
$ta=rand(0,100);
echo '<div class="co_div" style="background: '.a($a, $ta).';"></div>';
}
?>
.co_div {
width: 20px;
height: 20px;
float: left;
margin-right: 1px;
margin-top: 1px;
}
</style>
<?php
function a($r, $a){
foreach($r as $k=>$v)$n[$k]=$v+(255-$v)*$a/100;
return sprintf('#%02X%02X%02X', $n[0], $n[1], $n[2]);
}
$m=150;
$a[]=rand($m,255);
$a[]=rand($m,255);
$a[]=rand($m,255);
if(min($a)>240)$a[rand(0,2)]=rand($m, 240);
for($i=0;$i<2000;$i++){
$ta=rand(0,100);
echo '<div class="co_div" style="background: '.a($a, $ta).';"></div>';
}
?>
色彩列表:查看效果
<style>
.co_t {
width: 400px;
}
.co_div {
width: 20px;
height: 20px;
float: left;
margin-right: 1px;
margin-top: 1px;
}
</style>
<?php
$a=array(array('0', '3', '6'), array('9', 'c', 'f'));
$b=array('0', '3', '6', '9', 'c', 'f');
$c=array('0', '3', '6', '9', 'c', 'f');
echo '<div class="co_t">';
foreach($a as $ka=>$va){
foreach($b as $vb){
echo '<div class="co_div" style="background: #'.$vb.$vb.$vb.';"></div>';
foreach($va as $v){
foreach($c as $vc){
$t=$v.$vb.$vc;
echo '<div class="co_div" style="background: #'.$t.';"></div>';
}
}
}
}
echo '</div>';
?>
.co_t {
width: 400px;
}
.co_div {
width: 20px;
height: 20px;
float: left;
margin-right: 1px;
margin-top: 1px;
}
</style>
<?php
$a=array(array('0', '3', '6'), array('9', 'c', 'f'));
$b=array('0', '3', '6', '9', 'c', 'f');
$c=array('0', '3', '6', '9', 'c', 'f');
echo '<div class="co_t">';
foreach($a as $ka=>$va){
foreach($b as $vb){
echo '<div class="co_div" style="background: #'.$vb.$vb.$vb.';"></div>';
foreach($va as $v){
foreach($c as $vc){
$t=$v.$vb.$vc;
echo '<div class="co_div" style="background: #'.$t.';"></div>';
}
}
}
}
echo '</div>';
?>








