No details no source code and demo: source code demonstration source functioncut_str ($ string, $ sublen, $ filtertrue, $ start0, $ codeUTF-8) {if ($ filter) $ stringHtml2Text ($ string); if ($ codeUTF-8) {$ pa [x01-x7f] | [xc2-xdf] [x80-xbf] | [xe0-xef] [x80-xbf] {2} | [
No details, no source code, and Demonstration: source code demonstration function cut_str ($ string, $ sublen, $ filter = true, $ start = 0, $ code = 'utf-8 ') {if ($ filter) $ string = Html2Text ($ string); if ($ code = 'utf-8 ') {$ pa = "/[\ x01-\ x7f] | [\ xc2-\ xdf] [\ x80-\ xbf] | [\ xe0-\ xef] [\ x80- \ xbf] {2} | [
<无详细内容> <无>
Source code and demo:Source code source demonstration Source
function cut_str($string,$sublen,$filter=true,$start=0,$code='UTF-8'){if($filter) $string=Html2Text($string);if($code=='UTF-8'){$pa="/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";preg_match_all($pa,$string,$t_string);if(count($t_string[0])-$start>$sublen) return join('',array_slice($t_string[0],$start,$sublen))."...";return join('',array_slice($t_string[0],$start,$sublen));}else{$start=$start*2;$sublen=$sublen*2;$strlen=strlen($string);$tmpstr='';for($i=0;$i<$strlen;$i++){if($i>=$start&&$i<($start+$sublen)){if(ord(substr($string,$i,1))>129){$tmpstr.=substr($string,$i,2);}else{$tmpstr.=substr($string,$i,1);}}if(ord(substr($string,$i,1))>129) $i++;}if(strlen($tmpstr)<$strlen ) $tmpstr.="...";return $tmpstr;}}function Html2Text($str){$str = preg_replace("/
|
|
/isU","",$str);$alltext = "";$start = 1;for($i=0;$i
"){$start = 1;}else if($start==1){if($str[$i]=="<"){$start = 0;$alltext .= " ";}else if(ord($str[$i])>31){$alltext .= $str[$i];}}}$alltext = str_replace(" "," ",$alltext);$alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);$alltext = preg_replace("/[ ]+/s"," ",$alltext);return $alltext;}