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 do I remove trailing whitespace?


If you a string that contains trailing whitespace, most commonly because it has spaces at the end of it, then you will often want to tidy it up by removing that 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!



More strings PHP Questions

How do I format the output of a string?
What is the difference between ' and "?
How can I repeat a string variable several times?
How do I count how many times each character occurs in a string?
How do I print text to the screen?