CKTIS / PHP
rtrim()
Strip trailing bytes from a character set, stopping at the first other byte.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
rtrim(string $string, string $characters = " \n\r\t\v\x00"): stringStrip trailing bytes from a character set, stopping at the first other byte. The mask is not a suffix string, so rtrim with "xy" removes any trailing run of x or y. Leading bytes are retained. Use a suffix test plus slicing when one exact suffix must be removed.
Signature
rtrim(string $string, string $characters = " \n\r\t\v\x00"): string
Example output
[" data","bo","0012"]
Examples
<?php
echo json_encode([rtrim(" data\r\n"),rtrim("boxxyy","xy"),rtrim("001200","0")]);
Result
[" data","bo","0012"]