How can I remove trailing space from a string?
If you have just read about the trim function, then this example will illustrate the difference between the two functions by recycling the code from that example but with a simple substitution of 'trim' for 'chop':
<?php
$toomuchspace = " how are you ";
echo "<$toomuchspace>\n";
$thatsbetter = chop($toomuchspace);
echo "<$thatsbetter>";
?>
Prints this:
< how are you >
< how are you>
Notice that the leading space is still there - to get rid of that too, use trim.
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I find the last occurrence of a character in a string?how to compare strings in PHP?
How do I remove trailing whitespace?
How do I make the first letter of each word upper case?
How do I find the length of a string in PHP?
