PHP chop() Function

PHP chop() Function

The chop() function in PHP removes whitespaces or other predefined characters from the right end of the specified string.

Syntax

Parameter

str(required)– This parameter specifies the string to check.

charlist(optional)- This parameter represents which characters are to be to remove from the string. 
The following characters are removed if the charlist parameter is empty:

  • “\0” – NULL
  • “\t” – tab
  • “\n” – new line
  • “\x0B” – vertical tab
  • “\r” – carriage return
  • ” ” – ordinary white space

Return

This method returns the string after chopping the specified value from the string.

Example 1

Output

Example 2

Output

Example 3

Output