PHP chop() Function

Last Updated:

PHP chop()

The chop() function is used to remove the whitespaces and other predefined characters from the right side of a string.

It is an alias of rtrim() function.


PHP Compiler
<?php $str = "John "; // without chop() echo $str . "Doe <br>"; // with chop() echo chop($str) . "Doe"; ?>


chop(str, char_list)

Parameter Values

str Required Specifies the string to be trimmed.
char_list Optional Specifies the additional character(s) to remove from the string.
Without this parameter, the function removes the following characters.
  • ' ' - An ordinary space.
  • '\0' - The NUL byte
  • '\t' - tab
  • '\n' - line feed.
  • '\x0B' - a vertical tab.
  • '\r' - a carriage return.

Return Value

string Returns an altered string.

More Example


PHP Compiler
<?php $str = "John Doe"; echo chop($str, "Doe") . "<br>"; echo chop($str, "doe") . "<br>"; echo chop($str, "e") . "<br>"; ?>

Share this Page

Meet the Author