I'm confused with PHP functions rtrim()
and chop()
, as they work similar and give similar output. Why are there different functions for trimming trailing characters?
Sample examples:
PHP
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!") . "<br>"; //Hello
echo chop($str,"World!") . "<br>"; //Hello
Are there any differences between chop()
and rtrim()
functions?
The chop() function removes whitespaces or other predefined characters from the right end of a string.
PHP: chop() function This function is an alias of rtrim() function.
The answer is also in the manual: http://php.net/manual/en/aliases.php
And a quote from there:
However there are functions which changed names because of an API cleanup or some other reason and the old names are only kept as aliases for backward compatibility.
And chop()
is just a alias for rtrim()
so they do the same. This is also in the manual: http://php.net/manual/en/function.chop.php
A quote from there:
This function is an alias of: rtrim().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With