Trimming Strings in PHP


Remove whitespace or other characters from the start and end of a string with trim().

Source Code

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