The chop() in PHP is used to remove white spaces or any other specified characters from the end of a string.
string chop($string, $character)
Parameters: This function accepts two parameters as shown in the above syntax and are described below:
- $string : It is used to specify the string which is needed to be checked.
- $character : It specifies the character which is needed to be removed from the given string. If this parameter is not specified then NULL, tab, newline, vertical tab, carriage return and ordinary white space are removed automatically.
Return Value: The return type of the chop() function is string. It returns the string after removing the specified characters from the end.
Program 1: In the below program a string is initialized as hello geeks!, by using chop() function the characters – ‘s’ and ‘!’ are removed from the end of the string.
Hello Geeks! Hello Geek
Program 2: In the below program, since no character parameter is mentioned. Then automatically the newlines will be removed from the given string.
Hello Geeks! best wishes Hello Geeks! best wishesHello Geeks! best wishes
- How to get the function name inside a function in PHP ?
- p5.js | red() function
- PHP | Ds\Map first() Function
- p5.js | hue() function
- PHP | cos( ) Function
- PHP | sin( ) Function
- PHP | end() Function
- PHP | Ds\Map last() Function
- D3.js | d3.set.add() Function
- PHP | Ds\Map map() Function
- p5.js | int() function
- D3.js | d3.set.has() Function
- p5.js | log() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.