String Functions Flashcards
sprintf( string $format [, mixed $args] )
Returns a string formatted according to the conversion specifier used, which applies to $args.
strlen( string $subject )
Returns an integer representing the number of characters in string $subject
printf( string $format [, mixed $args] )
Just like sprintf(), except it prints the output directly to the output buffer rather than returning it for encapsulation in a var
str_pad( string $input, int $length, [, string $padding [, int $pad_type]] )
Returns the $input padded with enough spaces so that the total strlen is $length.
By default, a space character is used as the pad. Specify any other char with the $padding arg.
By default, padding is added to the end of the $input. This can be changed with the $pad_type arg.
strtolower( string $subject )
Returns a copy of $subject with all characters lowercased
strtoupper( string $subject )
Returns a copy of $subject with all characters uppercased
ucfirst( string $subject )
Returns a copy of $subject with only the first character of the first word capitalized
ucwords( string $subject )
Returns a copy of $subject with the first letter of every word capitalized
ltrim( string $subject [, string $character_list])
Returns a copy of $subject without leading white space (or $character_list).
$character_list can be a range by using ..
rtrim( string $subject [, string $character_list] )
Returns a copy of $subject without trailing white space (or $character_list)
$character_list can be a range by using ..
trim( string $subject [, string $character_list] )
Removes any white space (or $character_list) from in front if and behind $subject.
$character_list can be a range using ..
strcmp( string $str1, string $str2 )
Provides a more robust solution than == for comparing strings with binary content or multi-byte encoding.
Returns 0 if $str1 and $str2 are equal
Returns -1 if $str1 is alphabetically higher than $str2
Returns 1 if $str1 is alphabetically lower than $str2
Capitalized characters are considered alphabetically higher than their lowercased equivalent.
strncmp( string $str1, string $str2, int $length )
Like strcmp() except the $length argument specifies how much of each string is compared.
If $length = 4, then only the first 4 characters of $str1 and $str2 are compared.
strcasecmp( string $str1, string $str2 )
Just like strcmp() except case-insensitive.
strncasecmp( string $str1, string $str2, int $length )
Just like strncmp() except case-insensitive.
substr( string $source, int $start [, int $length] )
When called with $length, returns a substring of $source starting at index $start extending $length characters.
If no $length is specified, returns a substring of $source from index $start to end of the $source string.
If a negative $start is passed, the starting point is counted from the end of $source instead of from the beginning.
If a negative $length is passed, the returned string ends $length characters from the end of $source.
strpos( string $haystack, string $needle [, int $offset] )
Returns the index of $needle in $haystack, if found. If not found, returns FALSE.
Optional $offset is the index position from which to begin searching for $needle
Since this function may return 0 for a found character index, false positives may occur using == to compare output to FALSE. Use === instead.
strrpos( string $haystack, string $needle )
Returns the index of the last occurrence of $needle
strstr( string $haystack, string $needle )
Returns the portion of $haystack from the first occurrence of $needle to the end, if found. Returns FALSE if $needle is not found.
stristr( string $haystack, string $needle )
In a case-insensitive manner, returns the portion of $haystack from the first occurrence of $needle to the end of $haystack. Returns FALSE if $needle is not found.
strrchr( string $haystack, string $needle )
Only uses the first character of $needle to find its last occurrence in $haystack. If found, prints the remaining portion of $haystack from $needle to the end of $haystack to the end of $haystack. If not found, returns FALSE.
substr_replace( string $source, string $replace, int $start [, int $length] )
Returns a string that starts with $source and is replaced by $replace from index $start on.
If $length is specified, only $length characters of $source are $replaced from $start onward.
str_replace( mixed $search, mixed $replace, mixed $subject )
Searches $subject for all occurrences of $search and replaces them with $replace.
You can also pass in an array of $search strings and an array of corresponding $replace strings to search for and replace numerous different substrings of $subject.
strtr( string $subject, string $from, string $to )
OR
strtr( string $subject, array $map )
Translates characters in $subject from $from (list of characters to replace) to $to.
When an associative array is passed, it should contain key that serve as search values with corresponding values that serve as replacements.