Menu Close

chop() function PHP

4.5
(13)

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

How useful was this post?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 13

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Share

Posted in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

You can also read...