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 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.



Comment on this Question and Answer >>>

ASK A QUESTION

More strings PHP Questions

How do I find the last occurrence of a character in a string?

how to compare strings in PHP?

How do I remove trailing whitespace?

How do I make the first letter of each word upper case?

How do I find the length of a string in PHP?



Custom Search