Strings Flashcards
How would you “echo” and count the number of words in the string (“Hello World”)
echo str_word_count(“Hello World”);
How would you “echo” search for the text “World” in the string “Hello World”
echo strpos(“Hello World”, “World”);
What is the result of the following:
$x = “Hello World”;
echo strtoupper($x);
HELLO WORLD
How would you echo the following variable to lower case:
$x = “Hello World”;
echo strtolower($x);
How would you echo and replace “World” with “Dolly” in the following string:
$x = “Hello World”;
echo str_replace(“World”, “Dolly”, $x);
echo and Reverse the following:
$x = “Hello World”;
echo strrev($x);
Split $fruitString into an array using the “,” as the delimiter. Store the array in $fruitArray
$fruitString = “apple,banana,cherry”;
$fruitArray = explode(“,”, $fruitString);
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”;
$z = $x . “ “ . $y;