PHP Class LaravelBook\Laravel4Powerpack\Str

Show file Open project: laravelbook/laravel4-powerpack

Public Methods

Method Description
ascii ( string $value ) : string Convert a string to 7-bit ASCII.
camel ( string $value ) : string Convert a value to camel case.
camelCase ( string $value ) : string Convert a value to camel case.
classify ( string $value ) : string Convert a string to an underscored, camel-cased class name.
contains ( string $haystack, string | array $needle ) : boolean Determine if a given string contains a given sub-string.
endsWith ( string $haystack, string $needle ) : boolean Determine if a given string ends with a given needle.
extension ( $fileName ) : string Get a files extension from its path.
finish ( string $value, string $cap ) : string Cap a string with a single instance of a given value.
is ( string $pattern, string $value ) : boolean Determine if a given string matches a given pattern.
length ( $string ) : integer Get the length of a string.
limit ( string $value, integer $limit = 100, string $end = '...' ) : string Limit the number of characters in a string.
limitExact ( string $value, integer $limit = 100, string $end = '...' ) : string Limit the number of chracters in a string including custom ending
lower ( $string ) : string Convert a string to lowercase.
plural ( string $value, integer $count = 2 ) : string Get the plural form of the given word.
quickRandom ( integer $length = 16 ) : string Generate a "random" alpha-numeric string.
random ( integer $length, string $type = 'alnum' ) : string Generate a random alpha or alpha-numeric string.
segments ( string $value ) : array Return the "URI" style segments in a given string.
singular ( string $value ) : string Get the singular form of the given word.
slug ( string $title, string $separator = '-', $keepExtension = false ) : string Generate a URL friendly "slug" from a given string.
snake ( string $value, string $delimiter = '_' ) : string Convert a string to snake case.
startsWith ( string $haystack, string $needle ) : boolean Determine if a string starts with a given needle.
title ( $string ) : string Convert a string to title case (ucwords equivalent).
upper ( $string ) : string Convert a string to uppercase.
upperWords ( string $string ) : string Convert first letter of each word to uppercase.
words ( string $value, integer $words = 100, string $end = '...' ) : string Limit the number of words in a string.
wordwrap ( string $string, $length ) : string Adds a space to a string after a given amount of contiguous, non-whitespace characters.

Protected Methods

Method Description
pool ( string $type ) : string Get the character pool for a given type of random string.

Method Details

ascii() public method

This is helpful for converting UTF-8 strings for usage in URLs, etc.
public ascii ( string $value ) : string
$value string
return string

camel() public static method

Convert a value to camel case.
public static camel ( string $value ) : string
$value string
return string

camelCase() public method

Convert a value to camel case.
public camelCase ( string $value ) : string
$value string
return string

classify() public method

This method is primarily used to format task and controller names. Returns "Task_Name" $class = Str::classify('task_name'); Returns "Taylor_Otwell" $class = Str::classify('taylor otwell')
public classify ( string $value ) : string
$value string
return string

contains() public method

Determine if a given string contains a given sub-string.
public contains ( string $haystack, string | array $needle ) : boolean
$haystack string
$needle string | array
return boolean

endsWith() public method

Determine if a given string ends with a given needle.
public endsWith ( string $haystack, string $needle ) : boolean
$haystack string
$needle string
return boolean

extension() public method

Get a files extension from its path.
public extension ( $fileName ) : string
return string $string

finish() public method

Cap a string with a single instance of a given value.
public finish ( string $value, string $cap ) : string
$value string
$cap string
return string

is() public method

Determine if a given string matches a given pattern.
public is ( string $pattern, string $value ) : boolean
$pattern string
$value string
return boolean

length() public method

Get the length of a string $length = Str::length('Taylor Otwell'); Get the length of a multi-byte string $length = Str::length('Τάχιστη')
public length ( $string ) : integer
return integer

limit() public method

Returns "Tay..." echo Str::limit('Taylor Otwell', 3); Limit the number of characters and append a custom ending echo Str::limit('Taylor Otwell', 3, '---');
public limit ( string $value, integer $limit = 100, string $end = '...' ) : string
$value string
$limit integer
$end string
return string

limitExact() public method

Returns "Taylor..." echo Str::limitExact('Taylor Otwell', 9); Limit the number of characters and append a custom ending echo Str::limitExact('Taylor Otwell', 9, '---');
public limitExact ( string $value, integer $limit = 100, string $end = '...' ) : string
$value string
$limit integer
$end string
return string

lower() public method

Convert a string to lowercase $lower = Str::lower('Taylor Otwell'); Convert a multi-byte string to lowercase $lower = Str::lower('Τάχιστη');
public lower ( $string ) : string
return string

plural() public method

Returns the plural form of "child" $plural = Str::plural('child', 10); Returns the singular form of "octocat" since count is one $plural = Str::plural('octocat', 1);
public plural ( string $value, integer $count = 2 ) : string
$value string
$count integer
return string

pool() protected method

Get the character pool for a given type of random string.
protected pool ( string $type ) : string
$type string
return string

quickRandom() public static method

Should not be considered sufficient for cryptography, etc.
public static quickRandom ( integer $length = 16 ) : string
$length integer
return string

random() public method

Generate a 40 character random alpha-numeric string echo Str::random(40); Generate a 16 character random alphabetic string echo Str::random(16, 'alpha');
public random ( integer $length, string $type = 'alnum' ) : string
$length integer
$type string
return string

segments() public method

Return the "URI" style segments in a given string.
public segments ( string $value ) : array
$value string
return array

singular() public method

Get the singular form of the given word.
public singular ( string $value ) : string
$value string
return string

slug() public method

Returns "this-is-my-blog-post" $slug = Str::slug('This is my blog post!'); Returns "this_is_my_blog_post" $slug = Str::slug('This is my blog post!', '_');
public slug ( string $title, string $separator = '-', $keepExtension = false ) : string
$title string
$separator string
return string

snake() public static method

Convert a string to snake case.
public static snake ( string $value, string $delimiter = '_' ) : string
$value string
$delimiter string
return string

startsWith() public method

Determine if a string starts with a given needle.
public startsWith ( string $haystack, string $needle ) : boolean
$haystack string
$needle string
return boolean

title() public method

Convert a string to title case $title = Str::title('taylor otwell'); Convert a multi-byte string to title case $title = Str::title('νωθρού κυνός');
public title ( $string ) : string
return string

upper() public method

Convert a string to uppercase $upper = Str::upper('Taylor Otwell'); Convert a multi-byte string to uppercase $upper = Str::upper('Τάχιστη');
public upper ( $string ) : string
return string

upperWords() public method

Convert first letter of each word to uppercase.
public upperWords ( string $string ) : string
$string string
return string

words() public method

Returns "This is a..." echo Str::words('This is a sentence.', 3); Limit the number of words and append a custom ending echo Str::words('This is a sentence.', 3, '---');
public words ( string $value, integer $words = 100, string $end = '...' ) : string
$value string
$words integer
$end string
return string

wordwrap() public method

Adds a space to a string after a given amount of contiguous, non-whitespace characters.
public wordwrap ( string $string, $length ) : string
$string string
return string