Skip to content

Conversation

@carlos-granados
Copy link

@carlos-granados carlos-granados commented Jan 16, 2026

Adds 6 new functions which can be used to work with string suffixes and prefixes:

function str_prefix_ensure(string $prefix, string $subject): string
function str_suffix_ensure(string $suffix, string $subject): string

Add a prefix or suffix to a string only if the string does not yet have it

function str_prefix_remove(string $prefix, string $subject): string
function str_suffix_remove(string $suffix, string $subject): string

Remove a prefix or suffix from a string if the string has it

function str_prefix_replace(string $prefix, string $replace, string $subject): string
function str_suffix_replace(string $suffix, string $replace, string $subject): string

Replace a prefix or suffix in a string it the string has it

@iluuu1994
Copy link
Member

Hi @carlos-granados. Thanks for your proposal. I think the addition of new string functions is controversial enough to warrant an RFC. See https://wiki.php.net/rfc/howto. I'm foreseeing some disagreements on naming / namespacing, among other things. The add_{suffix,prefix} functions are also pretty much pointless, unless you're working with higher order functions I guess.

@carlos-granados
Copy link
Author

Hi @carlos-granados. Thanks for your proposal. I think the addition of new string functions is controversial enough to warrant an RFC. See https://wiki.php.net/rfc/howto. I'm foreseeing some disagreements on naming / namespacing, among other things. The add_{suffix,prefix} functions are also pretty much pointless, unless you're working with higher order functions I guess.

Thank @iluuu1994 yes, I was planning to create an RFC and in fact I did not intend to create this PR. I wanted to first create it in my fork but it seems that somehow I made a mistake and created it here. Now that it is created I'll leave it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants