Menu Close

chop() function PHP

codeamend

The chop() function removes whitespaces or other predefined characters from the right end of a string.

This function is an alias of: rtrim().

Syntax

chop(string,charlist) 

Parameter Values

string : Specifies the string to check.

charlist : Specifies which characters to remove from the string.

Technical Details

Return Value : Returns the modified string.

PHP Version : 4+

Examples

<?php
$string = "Codeamend Team";
echo $string;
echo "<br>";
echo chop($string,"Team");
?>

Output : 
Codeamend Team
Codeamend 

Note

chop() is different than the Perl chop() function, which removes the last character in 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

Share

Posted in PHP

You can also read...