Why we use the chop() Function in PHP?

Why we use the chop() Function in PHP?

The chop() is a built-in function in PHP  and chop() is used to remove white spaces or any other specified characters at the end of a string.

Syntax:

string chop($Given_string, $Given_character)

Parameters: This function accepts two parameters as shown in the above syntax and are described below:

Why we are using the $Given_string Variable?

It is used to specify the string which we want to test.

Why we are using the $Given_character Variable?

It points to the character that we want to remove from the given string. Now, the question is that what will happen, If this parameter is not specified? The answer is very simple,  then the newline, carriage return, vertical tab, NULL, tab, and ordinary white space are removed automatically.

What is the Return Value of chop function?

In this example, the return type of the chop() function is a string. The chop() function 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.

Output

Welcome to T4TUTORIALS.COM Welcome to T4TUTORIALS.COM

Output

Welcome to! T4Tutorials Welcome to! T4TutorialsWelcome to! T4Tutorials

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]