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
chop(str,charlist)
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
Original string:Welcome to my new World! After using the By using 'chop()' Function New string: Welcome to my new World!
Example 2
Output
Hello World! Hello World!Lines are removed
Example 3
Output
Original string : Tutorial And Example After the 'chop()' functions New string: Tutorial And Example Nothing is chopped