chop / rtrim. Right spaces gone; left spaces remain.
ltrim. Left spaces gone; right spaces remain.
trim. Both ends cleaned.
Alias check.chop() and rtrim() print the same result.
Frequently Asked Questions
chop() removes characters from the end (right side) of a string. By default it strips whitespace characters such as spaces, tabs, and newlines. It does not remove anything from the beginning of the string.
string chop(string $string, string $characters = " \t\ \r\0\x0B"). The first argument is the input string; the optional second argument lists which characters to strip from the end.
Yes. chop() is an alias of rtrim(). They behave identically—both remove characters from the right end of a string only. Prefer rtrim() in new code for clearer naming.
chop() (like rtrim()) removes characters from the end only. trim() removes characters from both the beginning and the end. Use chop() when trailing junk is the problem; use trim() when you need both sides cleaned.
When you omit the second argument, chop() removes space, tab (\t), newline (\ ), carriage return (\r), NUL byte (\0), and vertical tab (\x0B).