php截取中文字符串

<html>
<head>
<title></title>
</head>
<body>
<?php
$str=’今天天气不错,’;
echo utf8Substr($str,0,4);
//截取utf8字符串 $str  要截取的字符串  $start开始截取的位置  $len截取的字符长度
function utf8Substr($str, $start, $len)
{
return preg_replace(‘#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,’.$from.’}’.
‘((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,’.$len.’}).*#s’,
‘$1’,$str);
}

?>
</body>
</html>

php二维数组排序

这个还是很给力的

<?php
function array_sort($arr,$keys,$type=’asc’){
$keysvalue = $new_array = array();
foreach ($arr as $k=>$v){
$keysvalue[$k] = $v[$keys];
}
if($type == ‘asc’){
asort($keysvalue);
}else{
arsort($keysvalue);
}
reset($keysvalue);
foreach ($keysvalue as $k=>$v){
$new_array[$k] = $arr[$k];
}
return $new_array;
}

$array = array(
array(‘name’=>’手机’,’brand’=>’诺基亚’,’price’=>1050),
array(‘name’=>’笔记本电脑’,’brand’=>’lenovo’,’price’=>4300),
array(‘name’=>’剃须刀’,’brand’=>’飞利浦’,’price’=>3100),
array(‘name’=>’跑步机’,’brand’=>’三和松石’,’price’=>4900),
array(‘name’=>’手表’,’brand’=>’卡西欧’,’price’=>960),
array(‘name’=>’液晶电视’,’brand’=>’索尼’,’price’=>6299),
array(‘name’=>’激光打印机’,’brand’=>’惠普’,’price’=>1200)
);

$ShoppingList = array_sort($array,’price’);
echo “<pre>”;
print_r($ShoppingList);
echo “</pre>”;
?>

js倒计时

<html>
<head>
</head>

<body>
<span id=”tim”></span>
</body>
</html>
<script type=”text/javascript”>

var tim=document.getElementById(“tim”);
var t=3;//倒计时时间,分钟为单位
//小时
var h=parseInt(t/60)>0?h=parseInt(t/60):0;
var m=parseInt(t%60);
//秒
var s=60;
function gettime(){
s=s-1;
tim.innerHTML=h+”小时”+m+”分”+s+”秒”;
if(s==0){
if((h==0)&&(m==0)&&(s==0)){
clearInterval(timmer);
return;
}
s=60;
}
if(s==60){m=m-1;
if((m==0)&&(h>0)){
h=h-1;
}
}
}
var timmer=setInterval(“gettime()”,1000);
</script>

css浮动DIV

/*浮动窗口*/
.gotop { background:url(./images/gotop.png);
color:#DEBD4A;
z-index:2;
center:0;
right:0px;
position:fixed;
bottom:200px;
text-align:left;
width:50px;
height:68px;
display:none;
/*margin-left:-26px;*/
_position:absolute;
/* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight);
/* for IE6 */ overflow:visible; }
.gotop:hover{background:url(./images/gotop1.png);}