Removing Whitespace from Both Ends of a String in PHP


Apply trim() to strip whitespace (or other characters) from the beginning and end of a string.

Source Code

$text = "  Hello World!  ";
$trimmedText = trim($text);
echo $trimmedText; // Outputs: "Hello World!"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments