* // Convert a string to lowercase * echo Str::lower('STOP YELLING'); * * // Convert a UTF-8 string to lowercase * echo Str::lower('Τάχιστη'); * * * @param string $value * @return string */ public static function lower($value) { if (function_exists('mb_strtolower')) { return mb_strtolower($value, Config::get('application.encoding')); } return strtolower($value); } /** * Convert a string to uppercase. * * * // Convert a string to uppercase * echo Str::upper('speak louder'); * * // Convert a UTF-8 string to uppercase * echo Str::upper('Τάχιστη'); * * * @param string $value * @return string */ public static function upper($value) { if (function_exists('mb_strtoupper')) { return mb_strtoupper($value, Config::get('application.encoding')); } return strtoupper($value); } /** * Convert a string to title case (ucwords equivalent). * * * // Convert a string to title case * echo Str::title('taylor otwell'); * * // Convert a UTF-8 string to title case * echo Str::title('Τάχιστη αλώπηξ'); * * * @param string $value * @return string */ public static function title($value) { if (function_exists('mb_convert_case')) { return mb_convert_case($value, MB_CASE_TITLE, Config::get('application.encoding')); } return ucwords(strtolower($value)); } /** * Get the length of a string. * * * // Get the length of a string * echo Str::length('taylor otwell'); * * // Get the length of a UTF-8 string * echo Str::length('Τάχιστη αλώπηξ'); * * * @param string $value * @return int */ public static function length($value) { if (function_exists('mb_strlen')) { return mb_strlen($value, Config::get('application.encoding')); } return strlen($value); } /** * Convert a string to 7-bit ASCII. * * * // Returns "Deuxieme Article" * echo Str::ascii('Deuxième Article'); * * * @param string $value * @return string */ public static function ascii($value) { $foreign = Config::get('ascii'); $value = preg_replace(array_keys($foreign), array_values($foreign), $value); return preg_replace('/[^\x09\x0A\x0D\x20-\x7E]/', '', $value); } /** * Generate a random alpha or alpha-numeric string. * * * // Generate a 40 character random, alpha-numeric string * echo Str::random(40); * * // Generate a 16 character random, alphabetic string * echo Str::random(16, 'alpha'); * * * @param int $length * @param string $type * @return string */ public static function random($length, $type = 'alnum') { $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; return substr(str_shuffle(str_repeat(($type == 'alnum') ? $pool.'0123456789' : $pool, 5)), 0, $length); } }