PHP trim()

Strip whitespace from beginning and end

Function Signature

string trim(string $string, string $characters = " \t\n\r\0\x0B")

Description

Strip whitespace from beginning and end. The trim() function is commonly used in PHP for string operations and provides reliable functionality across all PHP versions.

Return Value

Returns the trimmed string

Example Usage

Important Notes

ltrim() for left, rtrim() for right. Can specify custom characters to strip.

Common Use Cases

The trim() function is particularly useful when you need to strip whitespace from beginning and end. It's frequently used in data processing, validation, transformation, and manipulation tasks throughout PHP applications.

trim() FAQ

What does trim() return?

Returns the trimmed string

When should I use trim()?

Use trim() when you need to strip whitespace from beginning and end in your PHP code. It's a reliable built-in function available in all PHP versions.

Are there any gotchas with trim()?

ltrim() for left, rtrim() for right. Can specify custom characters to strip.