0
0
PHPprogramming~10 mins

Why string functions matter in PHP - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the string to uppercase.

PHP
<?php
$text = "hello world";
echo [1]($text);
?>
Drag options to blanks, or click blank then click option'
Astrtolower
Bstrtoupper
Cstrlen
Dsubstr
Attempts:
3 left
💡 Hint
Common Mistakes
Using strtolower will convert to lowercase, not uppercase.
Using strlen returns the length, not the changed string.
2fill in blank
medium

Complete the code to find the length of the string.

PHP
<?php
$text = "hello";
$length = [1]($text);
echo $length;
?>
Drag options to blanks, or click blank then click option'
Astrlen
Bsubstr
Cstrpos
Dstrtoupper
Attempts:
3 left
💡 Hint
Common Mistakes
Using strtoupper changes case but does not count characters.
Using strpos finds position of a substring, not length.
3fill in blank
hard

Fix the error in the code to get the first 3 characters of the string.

PHP
<?php
$text = "Programming";
echo [1]($text, 0, 3);
?>
Drag options to blanks, or click blank then click option'
Astrlen
Bstrpos
Cstrtoupper
Dsubstr
Attempts:
3 left
💡 Hint
Common Mistakes
Using strlen returns length, not a substring.
Using strpos finds position, not substring.
4fill in blank
hard

Fill both blanks to check if the word 'cat' is in the string and print its position.

PHP
<?php
$text = "The cat is sleeping.";
$pos = [1]($text, 'cat');
if ($pos !== [2]) {
    echo "Found at position: $pos";
} else {
    echo "Not found.";
}
?>
Drag options to blanks, or click blank then click option'
Astrpos
Bfalse
Ctrue
Dstrlen
Attempts:
3 left
💡 Hint
Common Mistakes
Checking against true instead of false causes wrong results.
Using strlen instead of strpos does not find position.
5fill in blank
hard

Fill both blanks to create a new string with the first letter uppercase and the rest lowercase.

PHP
<?php
$text = "hELLO";
$newText = [1]([2]($text));
echo $newText;
?>
Drag options to blanks, or click blank then click option'
Aucfirst
Bstrtolower
Cstrtoupper
Dstrlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using strtoupper first makes all letters uppercase.
Not converting to lowercase first keeps unwanted uppercase letters.