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

What is the usage of { } in string handling in php?

How do I count how many times each character occurs in a string?

How do I make sure a string is a certain length?

How do you hash the password in this php script: define(sb db user name, admin store); define(sb db password, mypassword);

How do I join strings together?



Custom Search