Complete the code to remove whitespace from the beginning and end of the string.
$text = " Hello World "; $trimmed = [1]($text); echo $trimmed;
The trim function removes whitespace from both ends of a string.
Complete the code to remove whitespace only from the beginning of the string.
$text = " Hello World "; $trimmedStart = [1]($text); echo $trimmedStart;
The ltrim function removes whitespace from the start (left side) of a string.
Fix the error in the code to remove whitespace only from the end of the string.
$text = " Hello World "; $trimmedEnd = [1]($text); echo $trimmedEnd;
The rtrim function removes whitespace from the end (right side) of a string.
Fill both blanks to create an array of trimmed words from the list, removing spaces from both ends.
$words = [" apple ", " banana", "cherry "]; $trimmedWords = array_map([1], $words); print_r($trimmedWords);
Using trim inside array_map removes spaces from both ends of each word.
Fill all three blanks to trim spaces from both ends and check if the trimmed string is empty.
$text = " "; $trimmed = [1]($text); if ($trimmed [2] '' ) { echo [3]; } else { echo 'Not empty'; }
First, trim removes spaces. Then, == compares to empty string. If true, print 'Empty string'.