On 24 June 2025 14:13:16 BST, Larry Garfield <la...@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 <la...@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

Reply via email to