$str='/闑鮹/login/..'
echo current(str_split($str,4))

解决方案 »

  1.   

    /闑鮹/login/.. 
    前4个是 /字字/
    要得到的是这两个字吧?用 / 分割字符串就得到了 嘿嘿 如果位置不固定 正则来的效率高也简单 
      

  2.   

    先ord判断一下就可以了。如果大于127就切两个。
    没有简单的方法,如果装了mb_string,可以.
      

  3.   

    用ord不行,我使用的unicode编码,ord判断ASCII码
      

  4.   

    function substr_cut($str_cut,$length = 2) {  
    if (strlen($str_cut) > $length){ 
    for($i=0; $i < $length; $i++)
    if (ord($str_cut[$i]) > 128) $i++;
    $str_cut = substr($str_cut,0,$i); 

    return $str_cut; 
    }$str_cut = '判o&r#d断一下就可以了';
    $cc = substr_cut($str_cut,'4');
    echo $cc;
      

  5.   

    不好意识没看清楚,你要切/&#38353;&#39865;/login/..得先用正则提取出\&+\#+\d{5};把这些提取出来判断一下位数再取后面的字符长度。
      

  6.   


    <?php
    preg_match("/(&#[0-9]+;|[a-z]+)(?1){3}/iU","&#38353;&#39865;login",$match);
    print_r($match); // ["&#38353;&#39865;lo","&#38353;"]
    /**
    * 你的意思没有表达得很清楚
    * 直接说 源字符串是什么 要的结果是什么样子就行
    * 还有一些特殊情况也要说明 比如那些字符串建有没其他字符 比如斜杠 数字什么的。
    * 你说的含糊的 我都不知到你那里面的斜杠是字符串还是你用来说明截取点的。
    */?>
    参考:
    http://topic.csdn.net/u/20080331/14/012e0988-5a54-4831-b88b-7c34d4a4f522.htmlhttp://topic.csdn.net/u/20080411/17/a978257c-ae4b-4247-ad0b-78f424ff7597.html
      

  7.   

    这个函数约绝对可以用,我一直在用,中文占两个长度,你可以试试,中英文通用,函数中对中英文进行了判断处理了function utf_substr($str,$len)
    {
    for($i=0;$i<$len;$i++) 
    {
    $temp_str=substr($str,0,1);
    if(ord($temp_str) > 127) 
    //截取字符串第一字符的ascii码是否大于127,0-127的128个ASCII码代表了字母数字即一些标点符号等,超过此范围则为需要以unicode码显示
    {
    $i++; 
    if($i<$len)
    {
    $new_str[]=substr($str,0,3);
    $str=substr($str,3);
    }
    }
    else
    {
    $new_str[]=substr($str,0,1);
    $str=substr($str,1);
    }
    }
    return join($new_str);
    }
      

  8.   

    unicode不能用ord判断,所以16楼的还是没有办法用啊
      

  9.   


    <?php
    preg_match_all("/(&#[0-9]+;|[a-z]+)/iU","/&#38353;&#39865;/login/",$match);
    $result = array_slice($match[1],0,4);
    $result = implode('',$result);
    echo $result;
    // String "&#38353;&#39865;lo"
    ?>
      

  10.   

    第一步:
    原码是html实体,可以先还原成html非实体,这样中文可以正常显示了第二步:中英文分离这个就多了,得看你的中英文是如何混排的,想要分成什么样的!可以字符串截取,也可以用正则用正则:英文就是26个字母构成的,中文则不是
      

  11.   

    function FSubstr($title,$start,$len="",$magic=true) 
    {
    /**
      *  powered by Smartpig
      *  mailto:[email protected]
      */
      
    $length = 0;
    if($len == "") $len = strlen($title);//判断起始为不正确位置
    if($start > 0)
    {
      $cnum = 0;
      for($i=0;$i<$start;$i++)
      {
       if(ord(substr($title,$i,1)) >= 128) $cnum ++;
      }
      if($cnum%2 != 0) $start--;
      
      unset($cnum);
    }if(strlen($title)<=$len) return substr($title,$start,$len);$alen   = 0;
    $blen = 0;$realnum = 0;for($i=$start;$i<strlen($title);$i++)
    {
      $ctype = 0;
      $cstep = 0;
      $cur = substr($title,$i,1);
      if($cur == "&")
      {
       if(substr($title,$i,4) == "&lt;")
       {
        $cstep = 4;
        $length += 4;
        $i += 3;
        $realnum ++;
        if($magic)
        {
         $alen ++;
        }
       }
       else if(substr($title,$i,4) == "&gt;")
       {
        $cstep = 4;
        $length += 4;
        $i += 3;
        $realnum ++;
        if($magic)
        {
         $alen ++;
        }
       }
       else if(substr($title,$i,5) == "&amp;")
       {
        $cstep = 5;
        $length += 5;
        $i += 4;
        $realnum ++;
        if($magic)
        {
         $alen ++;
        }
       }
       else if(substr($title,$i,6) == "&quot;")
       {
        $cstep = 6;
        $length += 6;
        $i += 5;
        $realnum ++;
        if($magic)
        {
         $alen ++;
        }
       }
       else if(substr($title,$i,6) == "&#039;")
       {
        $cstep = 6;
        $length += 6;
        $i += 5;
        $realnum ++;
        if($magic)
        {
         $alen ++;
        }
       }
       else if(preg_match("/&#(\d+);/i",substr($title,$i,8),$match))
       {
        $cstep = strlen($match[0]);
        $length += strlen($match[0]);
        $i += strlen($match[0])-1;
        $realnum ++;
        if($magic)
        {
         $blen ++;
         $ctype = 1;
        }
       }
      }else{
       if(ord($cur)>=128)
       {
        $cstep = 2;
        $length += 2;
        $i += 1;
        $realnum ++;
        if($magic)
        {
         $blen ++;
         $ctype = 1;
        }
       }else{
        $cstep = 1;
        $length +=1;
        $realnum ++;
        if($magic)
        {
         $alen++;
        }
       }
      }
      
      if($magic)
      {
       if(($blen*2+$alen) == ($len*2)) break;
       if(($blen*2+$alen) == ($len*2+1))
       {
        if($ctype == 1)
        {
         $length -= $cstep;
         break;
        }else{
         break;
        }
       }
      }else{
       if($realnum == $len) break;
      }
    }unset($cur);
    unset($alen);
    unset($blen);
    unset($realnum);
    unset($ctype);
    unset($cstep);return substr($title,$start,$length);
    }
      

  12.   

    http://bbs.lamp.org.cn
      

  13.   


    <?phpprint m_substr("ss还是dd",1,3);
    /*
    现写的,大概是酱紫
    */
    function m_substr($str)
    {
    preg_match_all("/[\x80-\xff]?./",$str,$arr);
    if(func_num_args() == 2)
    {
    $len1 = func_get_arg(1);
    return implode("",array_slice($arr[0],$len1));
    }
    if(func_num_args() >= 3)
    {
    $len1 = func_get_arg(1);
    $len2 = func_get_arg(2);
    return implode("",array_slice($arr[0],$len1,$len2));
    }

    }
    ?>