String Functions Flashcards

0
Q

sprintf( string $format [, mixed $args] )

A

Returns a string formatted according to the conversion specifier used, which applies to $args.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

strlen( string $subject )

A

Returns an integer representing the number of characters in string $subject

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

printf( string $format [, mixed $args] )

A

Just like sprintf(), except it prints the output directly to the output buffer rather than returning it for encapsulation in a var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

str_pad( string $input, int $length, [, string $padding [, int $pad_type]] )

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

strtolower( string $subject )

A

Returns a copy of $subject with all characters lowercased

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

strtoupper( string $subject )

A

Returns a copy of $subject with all characters uppercased

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ucfirst( string $subject )

A

Returns a copy of $subject with only the first character of the first word capitalized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ucwords( string $subject )

A

Returns a copy of $subject with the first letter of every word capitalized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ltrim( string $subject [, string $character_list])

A

Returns a copy of $subject without leading white space (or $character_list).

$character_list can be a range by using ..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

rtrim( string $subject [, string $character_list] )

A

Returns a copy of $subject without trailing white space (or $character_list)

$character_list can be a range by using ..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

trim( string $subject [, string $character_list] )

A

Removes any white space (or $character_list) from in front if and behind $subject.

$character_list can be a range using ..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

strcmp( string $str1, string $str2 )

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

strncmp( string $str1, string $str2, int $length )

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

strcasecmp( string $str1, string $str2 )

A

Just like strcmp() except case-insensitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

strncasecmp( string $str1, string $str2, int $length )

A

Just like strncmp() except case-insensitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

substr( string $source, int $start [, int $length] )

A

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.

16
Q

strpos( string $haystack, string $needle [, int $offset] )

A

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.

17
Q

strrpos( string $haystack, string $needle )

A

Returns the index of the last occurrence of $needle

18
Q

strstr( string $haystack, string $needle )

A

Returns the portion of $haystack from the first occurrence of $needle to the end, if found. Returns FALSE if $needle is not found.

19
Q

stristr( string $haystack, string $needle )

A

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.

20
Q

strrchr( string $haystack, string $needle )

A

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.

21
Q

substr_replace( string $source, string $replace, int $start [, int $length] )

A

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.

22
Q

str_replace( mixed $search, mixed $replace, mixed $subject )

A

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.

23
Q

strtr( string $subject, string $from, string $to )

OR

strtr( string $subject, array $map )

A

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.