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.