The chop() function is the pseudonym of rtrim(). This function was introduced in PHP3. chop() removes all trailing whitespace characters from the given string. These characters include the horizontal tab (\t), linefeed (\n), vertical tab (\013), carriage return (\r), and space (‘ ”) characters.
string chop(string string)
String stripped of trailing whitespace
Example 1: Remove trailing whitespace with chop().
<?php $string = "\t\tI am a Geek\t\t"; echo "Original string: '$string'\n", "chop()'d string: '", chop ($string), "'"; ?>
Original string: ' I am a Geek ' chop()'d string: ' I am a Geek'
<?php $text = “\t\t We are using chop :) ... “; $choped = chop($text); echo $choped.”
”; $choped = chop($text,” \t.”); echo $choped.”
The output of the above program is as follows:
We are using chop :) ... We are using chop :)
Note: chop() is different than the Perl chop() function, which removes the last character in the string.