How do I remove trailing whitespace?
The function of choice here would be chop, like so:
<?php
$contents = " I'm spaced out ";
echo "<$contents>\n";
echo "<" . chop($contents) . ">";
< I'm spaced out >
< I'm spaced out>
?>
Note that the trailing space has all been removed from the second line, and also that the leading space is still there... if you want to get rid of that, it's a job for trim!
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I one-way encrypt a string in PHP?How do I reverse a string in PHP?
How do I turn a string into an array?
I retrieve data from a Mysql database and insert it into a textfield form. The data that I retrieve have a / at the end of the string. The data in the database does not have this / in the data. How do I remove this /?
How do I convert newlines to HTML line break tags?
