How-To: Removing trailing whitespace from a string with php
Jul.11, 2008 in
Development, How To
Need to remove the trailing whitespace characters from a string in php? chomp() is how you do it in Perl, however in PHP it’s just as easy. Simply use rtrim():
// $string = "|my string with trailing whitespace |"
$string = rtrim($string);
// $string = "|my string with trailing whitespace|"
It’s that easy! There is also the trim() function which does the same at the start of the line. You can view the manual reference here.
Tags: Php

Leave a Reply