Strings Flashcards

1
Q

How would you “echo” and count the number of words in the string (“Hello World”)

A

echo str_word_count(“Hello World”);

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

How would you “echo” search for the text “World” in the string “Hello World”

A

echo strpos(“Hello World”, “World”);

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

What is the result of the following:

$x = “Hello World”;
echo strtoupper($x);

A

HELLO WORLD

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

How would you echo the following variable to lower case:

$x = “Hello World”;

A

echo strtolower($x);

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

How would you echo and replace “World” with “Dolly” in the following string:

$x = “Hello World”;

A

echo str_replace(“World”, “Dolly”, $x);

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

echo and Reverse the following:

$x = “Hello World”;

A

echo strrev($x);

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

Split $fruitString into an array using the “,” as the delimiter. Store the array in $fruitArray

$fruitString = “apple,banana,cherry”;

A

$fruitArray = explode(“,”, $fruitString);

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

Concatenate the following 2 strings below ensuring a space between the words and store it in a variable $z (NOTE don’t use double quotes).

$x = “Hello”;
$y = “World”;

A

$z = $x . “ “ . $y;

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