PHP chop() Function

The chop() function is used to remove whitespace or other predefined character from the right end of a string.

Syntax:


chop(string,charlist);
Parameter Description Required/Optional
String the string to be check Required
charlist charlist parameter is empty Optional

Example 1


<?php  
$str = "Hello World!";  
echo "Your string is :".$str."<br>";  
echo "By using 'chop()' Functions is your string is: ".chop($str,"World!");  
?>
    

Output

Your string is :Hello World! By using 'chop()' Functions is your string is: Hello

Example 2


<?php 
$str = "Hello World!";  
echo "Your string is :".$str."<br>";  
echo "By using 'chop()' Functions is your string is: ".chop($str);. 
?>
    

Output

Your string is :Hello World! By using 'chop()' Functions is your string is: Hello World!

Example 3


<?php  
$str = "Hello World!nn";  
echo "Your string is :".$str."<br>;  
echo "By using 'chop()' Functions is your string is: ".chop($str,"World!");
>?
    

Output

Your string is :Hello World! By using 'chop()' Functions is your string is: Hello World!