PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How can I remove trailing space from a string?


To do this, use the chop function.

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.



More strings PHP Questions

How do I replace a word in a string in PHP?
How do I calculate the metaphone of a string?
How do I convert newlines to HTML line break tags?
How do I remove trailing whitespace from a string?
How do I remove trailing whitespace?