Example 1 — Remove Trailing Spaces
The everyday use: clean up spaces and new lines at the end of text.
<?php
$text = "Hello, CodeToFun ";
$clean = rtrim($text);
echo "[" . $clean . "]", PHP_EOL; How It Works
- Start with trailing spaces. Three spaces end the text.
- Call rtrim with one argument. It uses the default whitespace list.
- Spaces are removed. Stripping stops at the last n.
- Brackets show the edges. There is no space before the closing bracket.

