Skip to content
PHP News
Search
Implemented PHP 8.6

Add Form Feed in Trim Functions

Adds the form feed character (\f) to the default set of characters that trim(), ltrim() and rtrim() strip.

Adding form feed in trim, ltrim and rtrim default character mask as outlined in the RFC in version 8.6?

Primary vote

25 Yes 0 No 100% approval

This poll has closed.

Accepted. Voting closed on March 6, 2026 with 25 in favor and 0 against, above the two-thirds majority it needed. It shipped in PHP 8.6.

Summary

When you call trim(), ltrim() or rtrim() without a second argument, they strip a default set of characters: space, tab, newline, carriage return, the NUL byte and the vertical tab. The form feed, "\f", isn't on that list. This RFC from Weilin Du adds it.

The RFC points out that \f is already treated as whitespace in plenty of places. The C function isspace(), which PHP uses internally, counts it, and so does PHP's own is_numeric(). Python, JavaScript, Rust and Go all strip it in their trim functions.

How it works

$str = "\fHello World\f";
var_dump(trim($str));

// Before
// string(13) "\fHello World\f"

// After
// string(11) "Hello World"

Only the default changes. If you pass your own list of characters, you get exactly what you asked for.

What it means for existing code

This is a backward compatibility break, but a small one. It only affects code that relies on trim() keeping a form feed at the start or end of a string.

A few tools need updates:

  • IDEs need to include \f in their tooltips for these functions.
  • Static analyzers may need new rules. For example, trim("\f") now returns an empty string.

Other trim-like behavior, such as PHP's filters, isn't part of this RFC. The RFC also notes that removing the NUL byte from the default list could be a separate RFC someday.

Our coverage