PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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!



Comment on this Question and Answer >>>

ASK A QUESTION

More strings PHP Questions

How do I add commas easily to a string of numbers?

How do I format the output of a string?

How do I calculate the metaphone of a string?

How do I remove trailing whitespace from a string?

How do I make the contents of a string upper case?



Custom Search