Complete the code to convert the string to uppercase.
<?php $text = "hello world"; echo [1]($text); ?>
The strtoupper function converts all characters in a string to uppercase.
Complete the code to find the length of the string.
<?php $text = "hello"; $length = [1]($text); echo $length; ?>
The strlen function returns the number of characters in a string.
Fix the error in the code to get the first 3 characters of the string.
<?php $text = "Programming"; echo [1]($text, 0, 3); ?>
The substr function extracts a part of the string starting at a position with a given length.
Fill both blanks to check if the word 'cat' is in the string and print its position.
<?php $text = "The cat is sleeping."; $pos = [1]($text, 'cat'); if ($pos !== [2]) { echo "Found at position: $pos"; } else { echo "Not found."; } ?>
strpos finds the position of a substring. It returns false if not found, so we check against false.
Fill both blanks to create a new string with the first letter uppercase and the rest lowercase.
<?php $text = "hELLO"; $newText = [1]([2]($text)); echo $newText; ?>
First, convert the whole string to lowercase with strtolower, then uppercase the first letter with ucfirst. The strtoupper option is a distractor here.