# Add form feed as a whitespace character in trim, ltrim and rtrim

- Thread: https://externals.io/message/129697
- Original archive: https://news-web.php.net/php.internals/129697
- Started by LamentXU on 2025-12-27T10:38:21+00:00
- Messages: 4
- RFC: Add Form Feed in Trim Functions (Implemented (PHP 8.6)) — https://externals.io/rfc/trim_form_feed.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #129697 — LamentXU — 2025-12-27T10:38:21+00:00

URL: https://externals.io/message/129697#129697

Hi Internals,

I have opened a Pull Request to add \f (form feed) to the list of characters stripped by default in `trim()`, `ltrim()`, and `rtrim()`.

Currently, the default behavior of `trim()` strips the following characters: \n, \r, \t, \v, \0, and space. The form feed character \f is notably missing, despite being widely recognized as a whitespace character (in python, rust...).

Although I think this change aligns `trim()` with standard whitespace definitions, it is technically a backward compatibility break. I am writing to check if there are any strong objections to this change or if it requires further discussion.

References:

Issue: https://github.com/php/php-src/issues/20783

Pull Request: https://github.com/php/php-src/pull/20788

Thanks,
Weilin Du

---

## #129700 — Ben Ramsey — 2025-12-27T18:17:41+00:00

URL: https://externals.io/message/129697#129700 · In reply to: #129697

> Hi Internals,
>
> I have opened a Pull Request to add \f (form feed) to the list of
> characters stripped by default in `trim()`, `ltrim()`, and `rtrim()`.
>
> Currently, the default behavior of `trim()` strips the following characters:
>  \n, \r, \t, \v, \0, and space. The form feed character \f is notably
> missing, despite being widely recognized as a whitespace character (in
> python, rust...).
> Although I think this change aligns `trim()` with standard whitespace
> definitions, it is technically a backward compatibility break. I am writing
> to check if there are any strong objections to this change or if it
> requires further discussion.
>
> References*:*
>
>    -
>
>    Issue: *https://github.com/php/php-src/issues/20783
>    <https://github.com/php/php-src/issues/20783>*
>    -
>
>    Pull Request: *https://github.com/php/php-src/pull/20788
>    <https://www.google.com/search?q=https://github.com/php/php-src/pull/20788>*
>
> Thanks,
> Weilin Du
>


Notably, `mb_trim()`, introduced in 8.4, includes `\f` in the list of
characters it trims.
https://www.php.net/mb_trim

I’m not opposed to this change, but the BC break could lead to really
difficult and tricky bugs in applications that rely on the form feed to be
retained. I can’t think of any use cases that would expect form feed to
remain after trimming, but there might be some.

On the other hand, many users might consider it a bug that form feed isn’t
trimmed, so this might be argued as a bug fix, especially since other
languages consider form feed as a whitespace character to remove in similar
situations.

I’m for this change, but on the fence about the BC break.

Cheers,
Ben

---

## #129705 — Morgan — 2025-12-27T22:53:20+00:00

URL: https://externals.io/message/129697#129705 · In reply to: #129697

> Hi Internals,
> 
> I have opened a Pull Request to add|\f| (form feed) to the list of 
> characters stripped by default in|trim()|,|ltrim()|, and|rtrim()|.
> 
> Currently, the default behavior of|trim()| strips the following 
> characters:|\n|,|\r|,|\t|,|\v|,|\0|, and space. The form feed character| 
> \f| is notably missing, despite being widely recognized as a whitespace 
> character (in python, rust...).
> 

Also in PHP, where `ctype_space()` recognises \f as whitespace as well as 
all of those that `trim()` removes. (As the name implies, of course, this 
is because \f is recognised as whitespace in C.)

---

## #129706 — Morgan — 2025-12-27T23:43:56+00:00

URL: https://externals.io/message/129697#129706 · In reply to: #129705

> 
> Also in PHP, where `ctype_space()` recognises \f as whitespace as well as 
> all of those that `trim()` removes. (As the name implies, of course, this 
> is because \f is recognised as whitespace in C.)

Uh, except of course for NUL, which `trim()` removes.
