格式化简介文字
@param string $str
@param string $default = '' 默认内容
@param number $leng = 50
@return string
188822
public static function stripDesc($str, $default = '', $leng = 50) {
		$str || $str = $default;

		$str = trim(str_replace(array("&nbsp;", "\r", "\n"), "", strip_tags($str)));
		$str && $str = mb_substr($str, 0, $leng, "utf-8");

		return $str;
	}
1234663
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
616012
public function asSecret(StringLength $length = null)
    {
        $this->checkDefaultType(function() { return ($this->default instanceof Secret); }, Secret::class);
        return $this->default;
    }
537750
public static String rtrim(String str, String defaultValue) {
	if (str == null) return defaultValue;
	int len = str.length();

	while ((0 < len) && (str.charAt(len - 1) <= ' ')) {
	    len--;
	}
	return (len < str.length()) ? str.substring(0, len) : str;
    }
809358
function substr($str,$start,$len=0) {
		if ($start<0)
			$start=$this->strlen($str)+$start;
		if (!$len)
			$len=$this->strlen($str)-$start;
		return preg_match('/^.{'.$start.'}(.{0,'.$len.'})/us',$str,$match)?
			$match[1]:FALSE;
	}
13780
static function buildFromString($str, $lowercase=true, $forceTagsClosed=true, $target_charset = self::DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=self::DEFAULT_BR_TEXT, $defaultSpanText=self::DEFAULT_SPAN_TEXT)
    {
        $dom = new Tree(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
        if (empty($str) or strlen($str) > self::MAX_FILE_SIZE)
        {
            $dom->clear();
            return false;
        }
        $dom->load($str, $lowercase, $stripRN);
        return $dom;
    }
876255
public static function length($len, $str, $compare = null)
    {
        $actualLen = strlen($str);
        switch ($compare) {
            case 'lte':
            case '<=':
                return $actualLen <= $len;
            case 'gte':
            case '>=':
                return $actualLen >= $len;
            case 'lt':
            case '<':
                return $actualLen < $len;
            case 'gt':
            case '>':
                return $actualLen > $len;
            default:
                return $actualLen == $len;
        }
    }
305756
public static function number($str)
    {
        if(is_array($str)){
            foreach($str as $key=>$val){
                $str[$key] = self::number($val);
            }
            return $str;
        }
        return filter_var($str, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND | FILTER_FLAG_ALLOW_SCIENTIFIC);
    }
870754
static public function PackStringWithLength($str)
    {
        $len = strlen($str);
        # UTF-8
        if (!self::ValidateUTF8($str)) {
            throw new Exception('Bad UTF-8 String');
        }
        return pack('n', $len) . $str;
    }
1171850
public static function char(String $str, Int $limit = 500, String $endChar = '...',  Bool $stripTags = false, String $encoding = "utf-8") : String
    {
        $str = trim($str);

        if( $stripTags === true )
        {
            $str = strip_tags($str);
        }

        $str = preg_replace("/\s+/", ' ', str_replace(["\r\n", "\r", "\n", "&nbsp;"], ' ', $str));

        if( mb_strlen($str, $encoding) <= $limit )
        {
            return $str;
        }
        else
        {
            return mb_substr($str, 0, $limit, $encoding).$endChar;
        }
    }
1205765
public static function absLength($str) {
		if (empty($str)) {
			return 0;
		}
		if (function_exists('mb_strlen')) {
			return mb_strlen($str,'utf-8');
		}
        preg_match_all("/./u", $str, $ar);
        return count($ar[0]);
	}
893721
public static function summary($str, $limit=100, $strip = false) {
		$str = ($strip == true) ? strip_tags($str) : $str;
		return static::truncate($str, $limit - 3, '...');
	}
163535
private function split(string $str) {
        $len = strlen($str);
        for ($i = 0; $i < $len; $i++) {
            $c = $str[$i];
            $n = ord($c);
            if (($n >> 7) == 0) {
                //0xxx xxxx, asci, single
                yield $c;
            } elseif (($n >> 4) == 15) { //1111 xxxx, first in four char
                if ($i < $len - 3) {
                    yield $c . $str[$i + 1] . $str[$i + 2] . $str[$i + 3];
                    $i += 3;
                }
            } elseif (($n >> 5) == 7) {
                //111x xxxx, first in three char
                if ($i < $len - 2) {
                    yield $c . $str[$i + 1] . $str[$i + 2];
                    $i += 2;
                }
            } elseif (($n >> 6) == 3) {
                //11xx xxxx, first in two char
                if ($i < $len - 1) {
                    yield $c . $str[$i + 1];
                    $i++;
                }
            }
        }
    }
556696
public static function java_truncate(string $str): string
    {
        if (strlen($str) > 955) {
            return substr($str, 0, 475).'[...]'.substr($str, -475);
        }

        return $str;
    }
1165255
public static function toNumber($str)
    {
        if (is_string($str)) {
            $str = preg_replace("~[^0-9-.]~", "", $str);
        }
        return (strpos($str, ".") === false)
            ? intval($str)
            : floatval($str);
    }
473081
private static function cutString(string $str): string
    {
        static $mb;
        if ($mb === null) {
            $mb = function_exists('mb_strlen');
        }
        if ($mb) {
            $len = mb_strlen($str, 'UTF-8');
        } else {
            $len = strlen($str);
        }
        if ($len > self::MAX_LEN) {
            if ($mb) {
                return mb_substr($str, 0, self::MAX_LEN, 'UTF-8').'...';
            } else {
                return substr($str, 0, self::MAX_LEN).'...';
            }
        }
        return $str;
    }
1325494
public static function markString($str): string
    {
        $str_len = strlen($str);
        $start = 6 < $str_len ? intval($str_len / 5) : $str_len - 4;
        $end = $str_len - $start * 3;
        
        return preg_replace('|(?<=.{' . $start . '})(.{' . $end . '}).*?|', str_pad('', $end, '*'), $str, 1);
    }