-
- /*
- trim removes spaces from both ends of a string,
- rtrim removes spaces from the right of a string,
- ltrim removes spaces from the left of a string.
- */
- echo trim("space")."
";
- echo rtrim("space")."
";
- echo ltrim("space")."
";
- ?>
Copy code
Method 2: Replace with regular expression, more powerful. PHP removes spaces from the beginning and end of a string (including full-width)
-
-
- $str=" Script Academy bbs.it-home.org ";
- $str = mb_ereg_replace('^( | )+', '', $str);
- $str = mb_ereg_replace('(|
-
-
|