php 限制字数用法

180it 2020-01-21 PM 2753℃ 0条
//去除无字数限制,为提高效率限字数为1000字
//增加判断如为空,返回相应的文字
if($_POST['info']){
    $str = preg_replace('/[\x80-\xff]{1,3}/', ' ', $_POST['info'], -1); //过滤
    $num = strlen($str);
    if($num<1030){
    /////
    }else{
    $info="您的字数超过1000文字,请删除一些文字在使用。";
    }
echo $info;
}



        $infocount=mb_strlen($info, 'UTF-8');
        //1000以内可用
        if($infocount<=990){
            $zh_en=$this->translate($info,'zh-CN','EN');
            $wyc=$this->translate($zh_en,'EN','zh-CN');
        }else{
            $wyc="超过字数限制,QQ群:200653131";//92行设置的字数
        }
        /* 
        
        
        //超过一千可用
        
        
        if($infocount<=1000){
            //如果小于或等于1000直接翻译
            $zh_en=$this->translate($info,'zh-CN','EN');
            $wyc=$this->translate($zh_en,'EN','zh-CN');

            
        }else{
            //如果大于于1000,每1000字符进行分割循环翻译
            $info = $this->mbStrSplit($info, 800);
            $arr=count($info);

            for($i=0;$i<$arr;$i++){
                
            $zh_en=$this->translate($info[$i],'zh-CN','EN');
            $wyc.=$this->translate($zh_en,'EN','zh-CN');
                
            }
            
        } */

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php 限制字数用法