Table of Contents

PHP RFC: Add Form Feed in Trim Functions

Introduction

The trim(), ltrim(), and rtrim() functions strip whitespace (or other characters) from the beginning and end of a string. When the second parameter ($characters) is omitted, these functions use a default set of characters.

Currently, this default set includes:

Notably missing from this list is “\f” (ASCII 12 (0x0C)), the Form Feed character.

This RFC proposes adding “\f” to the default list of characters stripped by trim(), ltrim(), and rtrim().

Proposal

The proposal is to include the Form Feed character (\f / 0x0C) in the default character mask for trim(), ltrim(), and rtrim(). Most modern programming languages treat \f as whitespace in their trimming functions. Aligning PHP with this behavior reduces cognitive load for developers working in polyglot environments.

The Form Feed character is widely recognized as whitespace.

Examples

<?php
 
// Current Behavior
$str = "\fHello World\f";
var_dump(trim($str));
// string(13) "\fHello World\f"
 
// Proposed Behavior
$str = "\fHello World\f";
var_dump(trim($str));
// string(11) "Hello World"
 
?>

Backward Incompatible Changes

This is a backward incompatible change. Scripts that rely on trim() preserving leading or trailing Form Feed characters will be affected.

Proposed PHP Version(s)

PHP 8.6

RFC Impact

To the Ecosystem

There are several impacts to the ecosystem (mostly minor impacts):

To Existing Extensions

Existing extensions should not require recompilation.

To SAPIs

There is no specific impact on any SAPI (CLI, FPM, Apache, etc.). The change is limited to the string manipulation logic within the standard library.

Open Issues

Currently no open issues ongoing.

Future Scope

This RFC only focus on php function trim, ltrim and rtrim but not on other trimming functions implemented in php (such as in php filters).

Also, in the future there may be a new discussion about removing the NULL character (ASCII 0) from the default list of characters stripped by trim, ltrim and rtrim in a separated RFC.

Voting Choices

The voting will start after the cool-down period (expected 3 weeks, at Sat 18th Jan 2026 if no new issue(s) is raised).


Primary Vote requiring a 2/3 majority to accept the RFC:

Add form feed in trim, ltrim and rtrim default character mask as outlined in the RFC?
Real name Yes No Abstain
Final result: 0 0 0
This poll has been closed.

Patches and Tests

Implementation

The RFC hasn't been accepted yet.

References

* Internal discussion

Rejected Features

None for now.

Changelog

2025/12/29: Initial version. 2025/12/29: Change typos and expressions, also title.