Easy Tutorial
❮ Func Filesystem Rmdir Func Misc Defined ❯

PHP rtrim() Function

PHP String Reference Manual

Example

Remove characters from the right side of a string:


Definition and Usage

The rtrim() function removes whitespace or other predefined characters from the right side of a string.

Related functions:


Syntax

Parameter Description
string Required. Specifies the string to check.
charlist Optional. Specifies which characters to remove from the string. If omitted, this parameter, all of the following characters are removed: "\0" - NULL<br> "\t" - Tab<br> "\n" - Newline<br> "\x0B" - Vertical tab<br> "\r" - Carriage return<br> " " - Space

Technical Details

Return Value: Returns the modified string.
PHP Version: 4+
--- ---
Changelog: The charlist parameter was added in PHP 4.1.
--- ---

More Examples

Example 1

Remove spaces from the right side of a string:

The HTML output of the above code is (view source):

The browser output of the above code is:

Example 2

Remove newline characters (\n) from the right side of a string:

The HTML output of the above code is (view source):

The browser output of the above code is:


❮ Func Filesystem Rmdir Func Misc Defined ❯