[RFC] str_icontains

php.internals

Adam Cable

1 year ago
Hello internals, I'd like to present my first RFC - str_icontains, a case-insensitive friend of str_contains RFC: https://wiki.php.net/rfc/str_icontains PR (including tests): https://github.com/php/php-src/pull/18705 Previous discussion: https://externals.io/message/127504 Thanks, Adam

Jordi Boggiano

1 year ago
On 15.06.2025 22:12, Adam Cable wrote:
> I'd like to present my first RFC - str_icontains, a case-insensitive > friend of str_contains > > RFC: https://wiki.php.net/rfc/str_icontains > PR (including tests): https://github.com/php/php-src/pull/18705
Just a +1 from my side. Looks good, useful and I've definitely caught myself skipping the strtolower out of laziness and "it'll probably be fine" in the past :) Best, Jordi

Larry Garfield

1 year ago
On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote:
> Hello internals, > > I'd like to present my first RFC - str_icontains, a case-insensitive > friend of str_contains > > RFC: https://wiki.php.net/rfc/str_icontains > PR (including tests): https://github.com/php/php-src/pull/18705 > > Previous discussion: https://externals.io/message/127504 > > Thanks, > Adam
When str_contains() was added, a case-insensitive version was deliberately omitted in favor of "just use strtolower() yourself." Have you gone back to see the arguments for that to determine if they're still relevant? (I don't recall the details; I think one of them was function count explosion, but I think there were more.) --Larry Garfield

youkidearitai

1 year ago
2025年6月24日(火) 9:00 Larry Garfield <larry@garfieldtech.com>:
> > On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote: > > Hello internals, > > > > I'd like to present my first RFC - str_icontains, a case-insensitive > > friend of str_contains > > > > RFC: https://wiki.php.net/rfc/str_icontains > > PR (including tests): https://github.com/php/php-src/pull/18705 > > > > Previous discussion: https://externals.io/message/127504 > > > > Thanks, > > Adam > > When str_contains() was added, a case-insensitive version was deliberately omitted in favor of "just use strtolower() yourself." Have you gone back to see the arguments for that to determine if they're still relevant? > > (I don't recall the details; I think one of them was function count explosion, but I think there were more.) > > --Larry Garfield
Hi I have concerns from multibyte(Unicode) user. As someone who relies on Unicode, I feel that it is not worth using that function. str_contains can matches binary, so this is benefit of many reason, but str_icontains is only support ASCII. This only benefits some regions. Regards Yuya
-- --------------------------- Yuya Hamada (tekimen) - https://tekitoh-memdhoi.info - https://github.com/youkidearitai -----------------------------

Adam Cable

1 year ago
On Tue, Jun 24, 2025 at 1:56 AM youkidearitai <youkidearitai@gmail.com> wrote:
> 2025年6月24日(火) 9:00 Larry Garfield <larry@garfieldtech.com>: > > > > On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote: > > > Hello internals, > > > > > > I'd like to present my first RFC - str_icontains, a case-insensitive > > > friend of str_contains > > > > > > RFC: https://wiki.php.net/rfc/str_icontains > > > PR (including tests): https://github.com/php/php-src/pull/18705 > > > > > > Previous discussion: https://externals.io/message/127504 > > > > > > Thanks, > > > Adam > > > > When str_contains() was added, a case-insensitive version was > deliberately omitted in favor of "just use strtolower() yourself." Have > you gone back to see the arguments for that to determine if they're still > relevant? > > > > (I don't recall the details; I think one of them was function count > explosion, but I think there were more.) > > > > --Larry Garfield > > Hi > I have concerns from multibyte(Unicode) user. > > As someone who relies on Unicode, I feel that it is not worth using > that function. > str_contains can matches binary, so this is benefit of many reason, > but str_icontains is only support ASCII. > This only benefits some regions. > > Regards > Yuya > > -- > --------------------------- > Yuya Hamada (tekimen) > - https://tekitoh-memdhoi.info > - https://github.com/youkidearitai > ----------------------------- >
Hi Yuya, Thanks for your message. I totally appreciate the multibyte issue here. I've detailed about it in the RFC. This function is there just to help those that expect it to be available as parity to strpos, strstr that have ASCII case-folding case-insensitive versions available. Thanks, Adam

Adam Cable

1 year ago
On Tue, Jun 24, 2025 at 12:20 AM Larry Garfield <larry@garfieldtech.com> wrote:
> On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote: > > Hello internals, > > > > I'd like to present my first RFC - str_icontains, a case-insensitive > > friend of str_contains > > > > RFC: https://wiki.php.net/rfc/str_icontains > > PR (including tests): https://github.com/php/php-src/pull/18705 > > > > Previous discussion: https://externals.io/message/127504 > > > > Thanks, > > Adam > > When str_contains() was added, a case-insensitive version was deliberately > omitted in favor of "just use strtolower() yourself." Have you gone back > to see the arguments for that to determine if they're still relevant? > > (I don't recall the details; I think one of them was function count > explosion, but I think there were more.) > > --Larry Garfield >
Thanks Larry. Yes, I did spend time reading through the past discussions on both str_contains and the str_starts/end_with functions. I think initial RFCs failed because (a) people felt that the functions didn't necessarily bring a whole heap of functionality above userland code and (b) the debate about whether case-insensitive versions should be included. Now that these functions exist, it seems weird as a PHP user that case-insensitive versions aren't available to easily switch between. Obviously we have the UTF-8 question that I've detailed, but I'm hoping adding this will solve a tiny issue where people expect this function to exist, but it doesn't. Adam

Larry Garfield

1 year ago
On Tue, Jun 24, 2025, at 3:18 AM, Adam Cable wrote:
> On Tue, Jun 24, 2025 at 12:20 AM Larry Garfield <larry@garfieldtech.com> wrote: >> On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote: >> > Hello internals, >> > >> > I'd like to present my first RFC - str_icontains, a case-insensitive >> > friend of str_contains >> > >> > RFC: https://wiki.php.net/rfc/str_icontains >> > PR (including tests): https://github.com/php/php-src/pull/18705 >> > >> > Previous discussion: https://externals.io/message/127504 >> > >> > Thanks, >> > Adam >> >> When str_contains() was added, a case-insensitive version was deliberately omitted in favor of "just use strtolower() yourself." Have you gone back to see the arguments for that to determine if they're still relevant? >> >> (I don't recall the details; I think one of them was function count explosion, but I think there were more.) >> >> --Larry Garfield > > Thanks Larry. > > Yes, I did spend time reading through the past discussions on both > str_contains and the str_starts/end_with functions. > I think initial RFCs failed because (a) people felt that the functions > didn't necessarily bring a whole heap of functionality above userland > code and (b) the debate about whether case-insensitive versions should > be included. > > Now that these functions exist, it seems weird as a PHP user that > case-insensitive versions aren't available to easily switch between. > Obviously we have the UTF-8 question that I've detailed, but I'm hoping > adding this will solve a tiny issue where people expect this function > to exist, but it doesn't. > > Adam
A discussion of that, and why you think the new position outweighs the original decision, should be included in the RFC. (At the moment I'm undecided; yeah it's an easy enough utility to add, but the UTF-8 issue is real, and one could easily argue that it's stripos() that's wrong, because it's misleading as it only works on ASCII.) The ideal answer would be Derick's built-in String object RFC, which I don't think has been touched in a while, sadly... --Larry Garfield

Derick Rethans

1 year ago
On 24 June 2025 14:13:16 BST, Larry Garfield <larry@garfieldtech.com> wrote:
>On Tue, Jun 24, 2025, at 3:18 AM, Adam Cable wrote: >> On Tue, Jun 24, 2025 at 12:20 AM Larry Garfield <larry@garfieldtech.com> wrote: >>> On Sun, Jun 15, 2025, at 3:12 PM, Adam Cable wrote: >>> > Hello internals, >>> > >>> > I'd like to present my first RFC - str_icontains, a case-insensitive >>> > friend of str_contains >>> > >>> > RFC: https://wiki.php.net/rfc/str_icontains >>> > PR (including tests): https://github.com/php/php-src/pull/18705 >>> > >>> > Previous discussion: https://externals.io/message/127504 >>> > >>> > Thanks, >>> > Adam >>> >>> When str_contains() was added, a case-insensitive version was deliberately omitted in favor of "just use strtolower() yourself." Have you gone back to see the arguments for that to determine if they're still relevant? >>> >>> (I don't recall the details; I think one of them was function count explosion, but I think there were more.) >>> >>> --Larry Garfield >> >> Thanks Larry. >> >> Yes, I did spend time reading through the past discussions on both >> str_contains and the str_starts/end_with functions. >> I think initial RFCs failed because (a) people felt that the functions >> didn't necessarily bring a whole heap of functionality above userland >> code and (b) the debate about whether case-insensitive versions should >> be included. >> >> Now that these functions exist, it seems weird as a PHP user that >> case-insensitive versions aren't available to easily switch between. >> Obviously we have the UTF-8 question that I've detailed, but I'm hoping >> adding this will solve a tiny issue where people expect this function >> to exist, but it doesn't. >> >> Adam > >A discussion of that, and why you think the new position outweighs the original decision, should be included in the RFC. > >(At the moment I'm undecided; yeah it's an easy enough utility to add, but the UTF-8 issue is real, and one could easily argue that it's stripos() that's wrong, because it's misleading as it only works on ASCII.) > >The ideal answer would be Derick's built-in String object RFC, which I don't think has been touched in a while, sadly... > >--Larry Garfield
That lives here, and ought to work fine as an extension for PHP 8.3+: <https://github.com/derickr/php-text> It works on graphemes, groups of Unicode code points that make up a letter. It also handles strings in multiple locales. It doesn't yet have a contains method. cheers Derick

Adam Cable

1 year ago
On Sun, 15 Jun 2025, 9:12 pm Adam Cable, <adamcable@gmail.com> wrote:
> Hello internals, > > I'd like to present my first RFC - str_icontains, a case-insensitive > friend of str_contains > > RFC: https://wiki.php.net/rfc/str_icontains > PR (including tests): https://github.com/php/php-src/pull/18705 > > Previous discussion: https://externals.io/message/127504 > > Thanks, > Adam >
I'll likely put this to a vote today/tomorrow as most issues have been discussed, and hopefully people can now have a balanced view about whether it's worth including. Thanks for all the feedback, really appreciate it. Adam