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";
?>
Output
John Doe
JohnDoe
Syntax
chop(str, char_list)
Parameter Values
Value | Type | Explanation |
---|---|---|
str | Required | Specifies the string to be trimmed. |
char_list | Optional | Specifies the additional character(s) to remove from the string. Without this parameter, the function removes the following characters.
|
Return Value
Value | Explanation |
---|---|
string | Returns 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>";
?>
Output
John
John D
John Do
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.