php常用函数 要看的<br />
截取指定长度字符<br />
function cutstr($string, $length, $dot = ' ...') {<br />
if(strlen($string) <= $length) {<br />
return $string;<br />
}<br />
$string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);<br />
$strcut = '';<br />
if(strtolower(UC_CHARSET) == 'utf-8') {<br />
$n = $tn = $noc = 0;<br />
while($n < strlen($string)) {<br />
$t = ord($string[$n]);<br />
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {<br />
$tn = 1; $n++; $noc++;<br />
} elseif(194 <= $t && $t <= 223) {<br />
$tn = 2; $n += 2; $noc += 2;<br />
} elseif(224 <= $t && $t < 239) {<br />
$tn = 3; $n += 3; $noc += 2;<br />
} elseif(240 <= $t && $t <= 247) {<br />
$tn = 4; $n += 4; $noc += 2;<br />
} elseif(248 <= $t && $t <= 251) {<br />
$tn = 5; $n += 5; $noc += 2;<br />
} elseif($t == 252 || $t == 253) {<br />
$tn = 6; $n += 6; $noc += 2;<br />
} else {<br />
$n++;<br />
}<br />
if($noc >= $length) {<br />
break;<br />
}<br />
}<br />
if($noc > $length) {<br />
$n -= $tn;<br />
}<br />
$strcut = substr($string, 0, $n);<br />
} else {<br />
for($i = 0; $i < $length; $i++) {<br />
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];<br />
}<br />
}<br />
$strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);<br />
return $strcut.$dot;<br />
}<br />
<br />
分页函数<br />
function page($num, $perpage, $curpage, $mpurl) {<br />
$multipage = '';<br />
$mpurl .= strpos($mpurl, '?') ? '&' : '?';<br />
if($num > $perpage) {<br />
$page = 10;<br />
$offset = 2;<br />
<br />
$pages = @ceil($num / $perpage);<br />
<br />
if($page > $pages) {<br />
$from = 1;<br />
$to = $pages;<br />
} else {<br />
$from = $curpage - $offset;<br />
$to = $from + $page - 1;<br />
if($from < 1) {<br />
$to = $curpage + 1 - $from;<br />
$from = 1;<br />
if($to - $from < $page) {<br />
$to = $page;<br />
}<br />
} elseif($to > $pages) {<br />
$from = $pages - $page + 1;<br />
$to = $pages;<br />
}<br />
}<br />
<br />
$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="first"'.$ajaxtarget.'>1 ...</a>' : '').<br />
($curpage > 1 && !$simple ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="prev"'.$ajaxtarget.'>&lsaquo;&lsaquo;</a>' : '');<br />
for($i = $from; $i <= $to; $i++) {<br />
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :<br />
'<a href="'.$mpurl.'page='.$i.($ajaxtarget && $i == $pages && $autogoto ? '#' : '').'"'.$ajaxtarget.'>'.$i.'</a>';<br />
}<br />
<br />
$multipage .= ($curpage < $pages && !$simple ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="next"'.$ajaxtarget.'>&rsaquo;&rsaquo;</a>' : '').<br />
($to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="last"'.$ajaxtarget.'>... '.$realpages.'</a>' : '').<br />
(!$simple && $pages > $page && !$ajaxtarget ? '<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=\''.$mpurl.'page=\'+this.value; return false;}" /></kbd>' : '');<br />
<br />
$multipage = $multipage ? '<div class="pages">'.(!$simple ? '<em>&nbsp;'.$num.'&nbsp;</em>' : '').$multipage.'</div>' : '';<br />
}<br />
return $multipage;<br />
}<br />
<br />
去斜杠函数<br />
function dstripslashes($string) {//去斜杠<br />
if(is_array($string)) {<br />
foreach($string as $key => $val) {<br />
$string[$key] = $this->dstripslashes($val);<br />
}<br />
} else {<br />
$string = stripslashes($string);<br />
}<br />
return $string;<br />
}<br />