How do I remove trailing whitespace from a string?
You've used ltrim to remove space from the left and you've used just good old trim on its to remove space from both ends, and therefore it makes sense that you use rtrim to remove it from the right side.
Just in case you're not sure how to use it, here is a very simple example indeed:
<?php
$str = "I have right space ";
echo "<$str>\n";
echo "<" . rtrim($str) . ">";
//<I have right space >
//<I have right space>
?>
As you can see from the angle brackets, the space at the right of the string has been removed from the second printint of the string. Note that if there had been leading whitespace, it would have remained.
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How can I remove spaces from around a string value?How can I remove trailing space from a string?
How do I remove trailing whitespace?
How do I convert relevant characters in a string to HTML entities?
How do I add commas easily to a string of numbers?
