trim()
function
Strips whitespace from both ends of a string. ltrim() strips left only; rtrim() strips right only.
Syntax
trim(string $string, string $characters = " \n\r\t\v\0"): string
Example
php
<?php
$str = ' Hello World ';
echo trim($str); // 'Hello World'
echo ltrim($str); // 'Hello World '
echo rtrim($str); // ' Hello World'
echo trim('***Hi***', '*'); // 'Hi'