PHP chop() Function

You are Here:

PHP chop()

The chop() function is used to remove the whitespaces and other predefined characters from the right side of a string.

It is an alias of rtrim() function.

Example

PHP Compiler
<?php $str = "John "; // without chop() echo $str . "Doe <br>"; // with chop() echo chop($str) . "Doe"; ?>

Syntax

chop(str, char_list)

Parameter Values

ValueTypeExplanation
strRequiredSpecifies the string to be trimmed.
char_listOptionalSpecifies the additional character(s) to remove from the string.
Without this parameter, the function removes the following characters.
  • ' ' - An ordinary space.
  • '\0' - The NUL byte
  • '\t' - tab
  • '\n' - line feed.
  • '\x0B' - a vertical tab.
  • '\r' - a carriage return.

Return Value

ValueExplanation
stringReturns an altered string.

More Example

Example

PHP Compiler
<?php $str = "John Doe"; echo chop($str, "Doe") . "<br>"; echo chop($str, "doe") . "<br>"; echo chop($str, "e") . "<br>"; ?>

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author