Re: Proposal for functions that handle prefixes and suffixes
| From: | Juris Evertovskis | Date: | Sat, 17 Jan 2026 14:29:40 +0000 |
| Subject: | Re: Proposal for functions that handle prefixes and suffixes | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129768@lists.php.net to get a copy of this message | ||
On 2026-01-16 21:16, Barel wrote:
function add_prefix(string $source, string $prefix): string function add_suffix(string $source, string $suffix): string Add a prefix or suffix to a string *only if the string does not yet have it*Hi, As the functions do not always *add* a prefix, I'd suggest to consider names like
ensure_prefix or enforce_prefix instead.
Something like ensure_str_starts_with or ensure_starts_with would be a nicer fit with the str_starts_with, but then it doesn't rhyme with the other prefix/suffix functions that well.
Otherwise I can only say that I've had to solve the same tasks in multiple projects, so I'd enjoy such functions being available in PHP itself.
BR,
Juris