zen-cart中的截取字符串的函数

来源:互联网 发布:大掌门江湖boss数据 编辑:程序博客网 时间:2024/05/15 05:45
////// Truncate a string  function zen_trunc_string($str = "", $len = 150, $more = 'true') {    if ($str == "") return $str;    if (is_array($str)) return $str;    $str = trim($str);    // if it's les than the size given, then return it    if (strlen($str) <= $len) return $str;    // else get that size of text    $str = substr($str, 0, $len);    // backtrack to the end of a word    if ($str != "") {      // check to see if there are any spaces left      if (!substr_count($str , " ")) {        if ($more == 'true') $str .= "...";        return $str;      }      // backtrack      while(strlen($str) && ($str[strlen($str)-1] != " ")) {        $str = substr($str, 0, -1);      }      $str = substr($str, 0, -1);      if ($more == 'true') $str .= "...";      if ($more != 'true' and $more != 'false') $str .= $more;    }    return $str;  }


原创粉丝点击