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
What is the usage of { } in string handling in php?How do I count how many times each character occurs in a string?
How do I make sure a string is a certain length?
How do you hash the password in this php script: define(sb db user name, admin store); define(sb db password, mypassword);
How do I join strings together?
