PHP Version
4+
/* Remove whitespace from both ends of a string */
$string = '   hello world   ';
$trimmed = trim($string);
var_dump($trimmed); // Output: string(11) "hello world"

/* Remove characters specified by a parameter */
$string = 'hello world';
$trimmed = trim($string, 'he');
var_dump($trimmed); // Output: string(9) "llo world"

/*
 * Caution: trim() does not properly handle multibyte characters,
 * such as Japanese characters, which may cause encoding issues.
 */
$string = 'ようこそ';
$trimmed = trim($string, 'よう');
var_dump($trimmed); // Output: string(4) "�そ"
trim(string $string, string $characters = " \n\r\t\v\x00"): string
 * Caution: trim() does not properly handle multibyte characters,
 * such as Japanese, which may cause garbled output.
 */
$string = 'ようこそ';
$trimmed = trim($string, 'よう');
var_dump($trimmed); // Output: string(4) "�そ"
$original_string = 'ようこそ。はじめまして!';
$trim_string = preg_replace('/^よう/u', '', $original_string);

var_dump($trim_string); // Output: string(30) "こそ。はじめまして!"
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$input = '   some value   ';
$cleaned_input = trim($input);
$query = "SELECT * FROM table WHERE column = '$cleaned_input'";
$lines = file('example.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$cleaned_lines = array_map(function($line) { return trim($line); }, $lines);