09 四 2009 @ 10:20 上午 

有时候显示的内容长度要限制一下,下面这个函数来自DZ,可以设定要截取自己指定长度的内容
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; 此处考虑到了用户操作DEL键,如果只是从数据库中取出内容显示的话,可以直接$strcut .= $string[$i]; 这样就可以了
function cutstr($string, $length) {
 $strcut = ”;
 if(strlen($string) > $length) {
  for($i = 0; $i < $length – 3; $i++) {
   $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  }
  return $strcut.’…’;
 } else {
  return $string;
 }
}
$string=’12345678901234567890′;
$length=10;
echo cutstr($string, $length);

相关文章:
div+css内容过长截取  :http://www.dyphp.com/?p=344

Posted By: 大宇
Last Edit: 28 八 2009 @ 07:37 下午

EmailPermalinkComments (0)
Tags
Tags: , , ,
Categories: discuz, php, php技巧
 30 三 2009 @ 6:17 下午 

此函数是DZ中的  类似PHP中的in_array函数的JS “in_array”,同样是检查一个值是否为数组元素,来是很好用的,具体如下:

<script>
function in_array(needle, haystack) {
 if(typeof needle == ’string’ || typeof needle == ‘number’) {
  for(var i in haystack) {
   if(haystack[i] == needle) {
     return true;
   }
  }
 }
 return false;
}

var arr = new Array(‘123′,’456′);
alert(in_array(‘789′,arr));
</script>
此函数的返回值为BOOL型

Posted By: 大宇
Last Edit: 30 三 2009 @ 06:17 下午

EmailPermalinkComments (0)
Tags
Tags: ,
Categories: js
 11 三 2009 @ 2:47 下午 

此函数是使用PHP中的implode函数自定义的,但是用起来要比implode要好用 

/*
*数组转换
*/
function implodeids($array) {
 if(!empty($array)) {
  return “‘”.implode(“‘,’”, is_array($array) ? $array : array($array)).”‘”;
 } else {
  return ”;
 }
}

Posted By: 大宇
Last Edit: 11 三 2009 @ 02:47 下午

EmailPermalinkComments (0)
Tags
Tags: ,
Categories: php, php函数, php技巧
 16 七 2008 @ 11:51 下午 

function writetocache($script, $cachenames, $cachedata = ”, $prefix = ‘cache_’) {
 global $authkey;
 if(is_array($cachenames) && !$cachedata) {
  foreach($cachenames as $name) {
   $cachedata .= getcachearray($name, $script);
  }
 }

 $dir = DISCUZ_ROOT.’./forumdata/cache/’;
 if(!is_dir($dir)) {
  @mkdir($dir, 0777);
 }
 if($fp = @fopen(“$dir$prefix$script.php”, ‘wb’)) {
  fwrite($fp, “<?php\n//Discuz! cache file, DO NOT modify me!”.
   ”\n//Created: “.date(“M j, Y, G:i”).
   ”\n//Identify: “.md5($prefix.$script.’.php’.$cachedata.$authkey).”\n\n$cachedata?>”);
  fclose($fp);
 } else {
  exit(‘Can not write to cache files, please check directory ./forumdata/ and ./forumdata/cache/ .’);
 }
}

Posted By: 大宇
Last Edit: 05 一 2009 @ 08:09 下午

EmailPermalinkComments (0)
Tags
Tags: ,
Categories: discuz, php
 15 七 2008 @ 5:27 下午 

if($_REQUEST['operate'] == “js”){
 $cacheFile = DISCUZ_ROOT . ‘./forumdata/cache/cache_counta.php’;
 if (($time – @filemtime($cacheFile)) > $cacheTime) {
  //查询当天评分总数
  $ltime = date(‘H 点 i 分’,time());
  $numRows = $db->query(“SELECT time FROM {$tablepre}grade WHERE time>=’$time0′ AND time<=’$time24′”);
  $count = $db->num_rows($numRows);
  $countbar = ‘$newcountbar = \’<a href=”plugin.php?identifier=counta&module=counta”>截至到’. $ltime .’,总共收到评分’. $count .’个, 点击请看详情</a>\’;’.”\n\n”;

  writetocache(“counta”, ”, $countbar);
 }
 require ($cacheFile);
 echo “document.write(‘$newcountbar’)”;
 exit();
}

<script type=”text/javascript” src=”plugin.php?identifier=counta&module=counta&operate=js”></script>

Posted By: 大宇
Last Edit: 05 一 2009 @ 08:10 下午

EmailPermalinkComments (0)
Tags
Tags: , , ,
Categories: discuz, php

 Last 50 Posts
Change Theme...
  • Users » 1
  • Posts/Pages » 165
  • Comments » 12
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

关于



    No Child Pages.

Linux命令手册



    No Child Pages.

php.ini配置



    No Child Pages.

Memcache协议



    No Child Pages.