# Proposal: Please consider introducing a new function |str_cut| to make fast cutting for a string

- Thread: https://externals.io/message/103113
- Original archive: https://news-web.php.net/php.internals/103113
- Started by zjz@zjz.name on 2018-09-01T10:59:47+00:00
- Messages: 2
- 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

---

## #103113 — zjz@zjz.name — 2018-09-01T10:59:47+00:00

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

Hello.

I'd like to suggest PHP introduce a new function |str_cut| to make fast cutting of a string.



If the user wants to cut a large string to a still-very-large string(say, cutting a 1KB string from a larger string),
|str_cut| would be a far more efficient alternative solution than |substr|:


str_cut($str, 1024) vs $str = substr($str, 0, 1024)

|str_cut| works by *directly* reseting the len value of the string.

And I have created a first-draft PR at https://github.com/php/php-src/pull/3483 , I am also going to create an RFC.

I am looking forward to your thoughts.


Zhang Junzhi

---

## #103133 — zjz@zjz.name — 2018-09-05T18:52:32+00:00

URL: https://externals.io/message/103113#103133 · In reply to: #103113

Christoph Becker just authored a StringBuilder extension which may serve as base for futher exploration at https://github.com/php/php-src/pull/3483#issuecomment-418696660

which I believe means a long-term effort to solve the issue in this respect.
I am also wondering if the StringBuilder can go into the agenda of PHP intervals. If so, is this str_cut still needed anyway?
Is StringBuilder just enough? Or both of them(StringBuilder and str_cut) are still okay to be provided?
Any thoughts?
I am happy to see either.



在2018年09月01 18時59分，"張俊芝"<zjz@zjz.name>寫道：

Hello.

I'd like to suggest PHP introduce a new function |str_cut| to make fast cutting of a string.



If the user wants to cut a large string to a still-very-large string(say, cutting a 1KB string from a larger string),
|str_cut| would be a far more efficient alternative solution than |substr|:


str_cut($str, 1024) vs $str = substr($str, 0, 1024)

|str_cut| works by *directly* reseting the len value of the string.

And I have created a first-draft PR at https://github.com/php/php-src/pull/3483 , I am also going to create an RFC.

I am looking forward to your thoughts.


Zhang Junzhi
