Example 1 — Remove Extra Spaces
The most common use: clean spaces around a value.
<?php
$name = " Asha ";
echo "[" . $name . "]", PHP_EOL;
echo "[" . trim($name) . "]", PHP_EOL; How It Works
- Original value. It has spaces on both sides.
- Print with brackets. Brackets make the spaces easy to see.
- Call trim(). It removes the edge spaces.
- Result. You get
[Asha].

