PHP chop() Function
Last Updated : 21 Jun, 2023
Improve
The chop() in PHP is used to remove white spaces or any other specified characters from the end of a string. Syntax:php Output:php Output:
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.
<?php
$s= "Hello Geeks!";
echo $s. "\n";
echo chop($s, "s!");
?>
Hello Geeks! Hello GeekProgram 2: In the below program, since no character parameter is mentioned. Then automatically the newlines will be removed from the given string.
<?php
$s= "Hello Geeks! \n best wishes \n \n";
echo $s;
echo chop($s);
echo $s;
?>
Hello Geeks! best wishes Hello Geeks! best wishesHello Geeks! best wishesReference: http://php.net/manual/en/function.chop.php