CKTIS / PHP
trim()
Strip matching bytes at both ends, leaving internal characters untouched.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
trim(string $string, string $characters = " \n\r\t\v\x00"): stringStrip matching bytes at both ends, leaving internal characters untouched. The default mask includes ASCII space, tab, line feed, carriage return, vertical tab and NUL. It does not strip every Unicode whitespace character. A custom mask is a character set and supports ranges.
Signature
trim(string $string, string $characters = " \n\r\t\v\x00"): string
Example output
["A B","id","c2a0"]
Examples
<?php
echo json_encode([trim("\0 A B \t"),trim("123id321","0..9"),bin2hex(trim("\u{00A0}"))]);
Result
["A B","id","c2a0"]