chop
Alias of rtrim
The chop()
function removes whitespace characters or other predefined characters at the right end of the string.
Remove characters from the right end of the string:
<?php $str = "Hello World!" ; echo $str . "<br>" ; echo chop ( $str , "World!" ) ; ?>
Try it yourself
Remove the newline character (\n) to the right of the string:
<?php $str = "Hello World!\n\n" ; echo $str ; echo chop ( $str ) ; ?>
The HTML output of the above code is as follows (see the source code):
< ! DOCTYPE html > < html > < body > Hello World ! Hello World ! < / body > < / html >
The browser output of the above code is as follows:
Hello World! Hello World! Hello World!
Try it yourself