Generate Text Except

@param string $str String.
@param mixed $args Arguments.

@arg int $length Length limit.
@arg string $unit Unit to examine, "character" or "word".
@arg string $suffix Suffix, e.g. ...

@return string Excerpt.
171601
public static function excerpt($str='', $args=null) {
		ref\cast::string($str, true);
		ref\sanitize::whitespace($str, 0);
		$str = \strip_tags($str);

		$options = data::parse_args($args, constants::EXCERPT);
		if ($options['length'] < 1) {
			return '';
		}

		$options['unit'] = \strtolower($options['unit']);
		switch (\substr($options['unit'], 0, 4)) {
			case 'char':
				$options['unit'] = 'character';
				break;
			case 'word':
				$options['unit'] = 'word';
				break;
		}

		// Character limit.
		if (
			('character' === $options['unit']) &&
			mb::strlen($str) > $options['length']
		) {
			$str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix'];
		}
		// Word limit.
		elseif (
			('word' === $options['unit']) &&
			\substr_count($str, ' ') > $options['length'] - 1
		) {
			$str = \explode(' ', $str);
			$str = \array_slice($str, 0, $options['length']);
			$str = \implode(' ', $str) . $options['suffix'];
		}

		return $str;
	}
828492
public static function getString(&$str)
    {
        $p = mb_orig_strpos($str, "\x00");
        if ($p === false) {
            return '';
        }
        $r = mb_orig_substr($str, 0, $p);
        $str = mb_orig_substr($str, $p + 1);
        return $r;
    }
1005255
private function MaxAge($str) {
    if (strpos($str, '.') === false) {
      throw new Exception('File has no extension');
    }
    $str = strrchr($str, '.');
    $str = substr($str, 1);
    return (integer) $str;
  }
711973
public function truncateHtml($str, $length, $suffix = '&hellip;')
    {
        $stringUitl = new StringUtil();

        return $stringUitl->truncatePreservingTags($str, $length, $suffix);
    }
893794
protected function toRegex($str)
    {
        $value = Expression::create($str);

        if ($value->isGlob()) {
            $value = $value->getRegex();

            if (false === strpos($str, '/')) {
                $value->setStartFlag(false);
            }
        }

        return $value->render();
    }
1338364
private function generateAppletTag($str) {
	$this->logDebug('generateAppletTag', 'Entering function');
	$str = preg_replace('/'.$this->classparams['tag_jscript'].'/', $this->str_jsinit(), $str);
	return preg_replace('/'.$this->classparams['tag_applet'].'/', $this->str_applet(), $str);
}
868513
public static String unquote(String str)
        throws Exception {
        int len = str.length();
        StringBuffer buf = new StringBuffer(len);
        boolean inQuotes = false;
        char c;
        int i = 0;

        if (str.charAt(i) == '"') {
            inQuotes = true;
            i++;
        }
        while(i < len) {
            c = str.charAt(i);
            if (inQuotes) {
                if (c == '"') {
                    inQuotes = false;
                } else if (c == '\\') {
                    buf.append(str.charAt(++i));
                } else {
                    buf.append(c);
                }
            } else {
                if (c == '\r') {
                    if (str.charAt(i++) != '\n') {
                        throw new Exception("Malformed string.");
                    }
                } else if (c == '"') {
                    inQuotes = true;
                    i++;
                } else {
                    buf.append(c);
                }
            }
            i++;
        }
        return buf.toString();
    }
1355241
private function splitArguments($str)
    {
        $str = trim($str);

        $args = array();
        if (!empty($str)) {
            preg_match_all('/[+-]?(\d*\.\d+|\d+)(e[+-]?\d+)?/', $str, $args);
            $args = $args[0];
        }

        return $args;
    }
276133
public static function stripAll($str)
    {
        $str = stripslashes($str);
        $str = strip_tags($str);
        $str = \sb\Strings::unicodeUrldecode($str);
        $str = self::stripBling($str);
        $str = \sb\Strings::stripMicrosoftChars($str);
        return $str;
    }
257209
protected static function strContains($str, array $arr)
    {
        foreach ($arr as $a) {
            if (stripos($str, $a) !== false) {
                return true;
            }
        }
        return false;
    }
352850
public static function cleanTextarea($str)
  {
    $str = str_replace('&nbsp;', ' ', $str);
    $str = preg_replace("/[\r\n]{2,}/", "\n\n", $str);
    $str = preg_replace("/<br([^>]*)>/", "\n", $str);
    
    if ( !preg_match("/<(p|table|figure|div|h[1-6])>.+<\/$1>/", $str) ){
      $str = '<p>'.$str.'</p>';
    }
    $str = preg_replace("/\n\n/", "</p> <p>", $str);
    $str = trim($str);
    $str = preg_replace("/<p>\s*<\/p>/", "", $str);
    $str = preg_replace("/\n/", "<br />", $str);
    $str = trim($str);
    
    return $str;
  }
552218
public static function quote($str)
    {
        static $flags;

        if (!$flags) {
            $flags = ENT_COMPAT;
            if (defined('ENT_SUBSTITUTE')) {
                $flags |= ENT_SUBSTITUTE;
            }
        }

        return @htmlspecialchars($str, $flags, RCUBE_CHARSET);
    }
1329623
public static function wordWrapEnable($str, $width)
    {
        if (!empty($str) && !empty($width) && $width >= 1) {
            return wordwrap($params['str'], $params['width'], '<br />\n');
        } else {
            return false;
        }
    }
1316806
private static function substr($str,$start,$length=null)
    {
        $ar = array();
        preg_match_all("/./u", $str, $ar);

        if($length != null) {
            return join("",array_slice($ar[0],$start,$length));
        } else {
            return join("",array_slice($ar[0],$start));
        }
    }
38541
private function escapeLikeString($str)
    {
        if (false !== strpos($str, '%')) {
            $str = str_replace("%", "\%", $str);
        }

        if (false !== strpos($str, '_')) {
            $str = str_replace("_", "\_", $str);
        }
        
        return $str;
    }
798196
public static function bin2str($str){
		self::checkLength($str);
		self::checkBin($str);

		preg_match_all('/.{8}/', $str, $chrs);
		$chrs = array_map('bindec', $chrs[0]);

		// I'm just being slack here
		array_unshift($chrs, 'C*');

		return call_user_func_array('pack', $chrs);
	}
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++;
                }
            }
        }
    }