$length必须输入吗?截取前怎么知道$length呢?没搞清楚这个函数的用途……

解决方案 »

  1.   

    to snmr_com(麒麟厍人) 
    请看清标题:中文字符串,我没有把每个字符集都包含进去,因为没那个必要,我们主要就是针对中文,除非有特殊需要,可以改一下,
    length是你要截取的长度,截取字符串的函数不都这几个参数?
      

  2.   

    /*
     * @todo 中文截取,支持gb2312,gbk,utf-8,big5 
     *
     * @param string $str 要截取的字串
     * @param int $start 截取起始位置
     * @param int $length 截取长度
     * @param string $charset utf-8|gb2312|gbk|big5 编码
     * @param $suffix 是否加尾缀
     */
      

  3.   

    还差BIG5-HKSCS
    能也补上吗?
      

  4.   

    我也发布一个吧,SMS对纯ACSII用7BIT压缩后再传送。
    这个是函数实现解压功能。
    function Decode7bit($str7bit)
    {
    for ($i=0; $i<strlen($str7bit);$i+=2)
    {
    $str = decbin(hexdec($str7bit[$i].$str7bit[$i+1]));
    $arrBin[] = sprintf("%08s", $str);
    }
    //print_r($arrBin);
    $i=0;
    $move =1;
    while ($i<count($arrBin)) {
    if ($i==0) {
    $dst = substr($arrBin[$i],$move);
    }elseif ($i%7==0 && $i!=0) {
    //special char
    switch ($left)
    {
    case '0000000':
    $left = '1000000';
    break;
    }
    $arrBinDst[] =$left;
    $strDst .=chr(bindec($left));
    $move=1;
    $left='';
    }
    $dst = substr($arrBin[$i],$move).$left;
    $left =substr($arrBin[$i],0,$move);
    $move++;
    $i++;
    //special char
    switch ($dst)
    {
    case '0000000':
    $dst = '1000000';
    break;
    }
    $arrBinDst[]=$dst;
    $strDst .=chr(bindec($dst));
    }
    //print_r($arrBinDst);
    return $strDst;
    }
      

  5.   

    $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
    可简化为
    $re['utf-8']   = "/[\x00-\x7f]|[\xc0-\xff][\x80-\xbf]+/";
      

  6.   

    高手都在这儿.我顺便在这儿问一个问题
    为什么我的apache(2.0.58)
    用SAPI模块,即
    LoadModule php5_module "c:/php/php5apache2.dll"
    AddType application/x-httpd-php .php
    这样的配置就行.用CGI模块,即
    ScriptAlias /php/ "C:/php"
    AddType application/x-httpd-php .php
    # For PHP 5
    Action application/x-httpd-php "/php/php-cgi.exe"
    怎么就不能解析PHP了呢?