Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127508 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 643961A00BC for ; Fri, 30 May 2025 07:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748589302; bh=fZwNtrqhF5X2ePHSaisMq+He0vXslRGpL2LDQ14Fxvw=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=awbwh55p7B85OOa2vqFBwWuX/L4S6DR2fmfL9aeJr0rMB7hqVSQC0S4oFa00hOHdE KT/mHbBDHw+QcWHGUhmwMpXNdGyGudcJZn8BVT/Z1QEwR4YhKYC8GbVs5OToGtHiXe 8Fiu5dude9PFpY95V1kMSHXHWovM1s60Ozd22Y/wcifH9N8+ZB1vj3MOasfjrVjJ6u uMz76Vu3IqJdu1Av0EJ2Wut3RibrV8wz7AQAt/JWVQ/yEssy3i5RztC03GCCIEk6uf HgRyD9ViP9jbu0GXcX+aA6S5q6JlxyH4AZznuAjd8ztGjPQhLXye2K/Fhv413YBgXF 2bXq//fbO394Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9E8E2180042 for ; Fri, 30 May 2025 07:15:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,MALFORMED_FREEMAIL,MISSING_HEADERS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 30 May 2025 07:15:01 +0000 (UTC) Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-6045e69c9a8so3046586a12.3 for ; Fri, 30 May 2025 00:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748589426; x=1749194226; darn=lists.php.net; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=8gdQQnRKP+NQXQNrz9dsc5mawyGCe8HrkalZMYF1uG4=; b=nbo5ijWFWZazuOCLP7WxyNqwR4jRMZzqzmyxBiH3woMto2GCrCRnY9q1bWduaNsd6q CIFWXCG3k0NSDK9QPEcevm/0NPTN800dqMFd3eRgrVMk/IvKkcBoc3PVUYkQleNcMYyS irXhAV5ZEX9tOxbYAtCEq/uOgmR5maWi2ROUUnOSNxQgZnwcZCD0xslFyBY8WhfsINYy YI/MXJjFPJL4baPBEDOwPzpLv5j4xkuKtO8ty8iCQ9XpKZSrBxb2MkNENd/TshLrKcpW 82V8iq5mqSIPb7EKZ/SsHKzOIrvBfDKqKZ4lF9cdz8RxmAiS5JXAMTz9pm1nNHgOZSCu rjaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748589426; x=1749194226; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8gdQQnRKP+NQXQNrz9dsc5mawyGCe8HrkalZMYF1uG4=; b=IZ6Sf7l8Wlwhr6whpRFJsR4nqpD6aajr27bJFkvAD4cdqKa2uCRrO40egLfVAVJVyO G23KPgvft9Qw4dS7oeiu8v3hSLoWWmfH5Lbr2DsKsfKX3+fAvoAxIcQUE0kPl7kg9Vy3 wSCbXFaYCOaHu6tLDaYZovRj36cG+Kw9tbA9hEtEBX3B3fAlbbm7re+/cw+U1XhD72sz mIit311Y4nKthtLmcM1K/1UxOb66SmgEz+ZUQoQM4FXdMqiIg2+ezwv5KOlDzHstFVj9 ELNwB0r74El0jEO3GXfR6okYyS7FgOarlqCWcO/g7ijjRFvtZONjWiQJtmQeNgpN9mn/ RMKQ== X-Gm-Message-State: AOJu0Yxp5T+1R11wvQLjpChg8U1FPlHgJBQNShvDHBp7YLyeB+KFCRQq mbpvSmC2w7Y+N0ul3JOOT8dlcqu6C0+KdBvdhHVObkAd6GviDeAd+6f7OSiOX7cxowpf76g3ter otDxhfvwNSvjgChDOp9kqZg3ZSWqYQYl2og== X-Gm-Gg: ASbGncux/zoo6UwssDdn9Mglp3MO4CVh971bADe//wNNFJfFr3QKThJq+gpb/tL8cKN XD8EqylRqFeWzoqgSqccJQWwt8ew8gZuFFNCOZSHfT1M6RcdbSzE+Vp/5ZaBu4z9QcgSQ+WVI1J LhP0oX//eIeRm3+8n5thc1FTZ682TOacT0 X-Google-Smtp-Source: AGHT+IHc/uRXIo1egz4NKiHtiYuHm2QmxhYvlpHyZO1t7wJE778+0zOuOiIqT5bTacJ6Hxt7Zp2XKS/0IQVSvcFyaqI= X-Received: by 2002:a17:907:2d91:b0:ad8:93a3:29ab with SMTP id a640c23a62f3a-adb3225daddmr210488566b.12.1748589425355; Fri, 30 May 2025 00:17:05 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 30 May 2025 08:16:54 +0100 X-Gm-Features: AX0GCFtQFk6f83W1gikZnqj1WnF6LARpRqUvqAJz6vcbTVEz-TdKPgUfZbSUiuA Message-ID: Subject: Re: [PHP-DEV] Adding in a case-insensitive version of str_contains Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000008e86f206365533a7" From: adamcable@gmail.com (Adam Cable) --0000000000008e86f206365533a7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 29, 2025 at 10:00=E2=80=AFPM Kamil Tekiela wrote: > As I understand, it was a conscious decision not to add this function > when str_contains was created. The reason is that case sensitivity is > locale-dependent, and for such use cases, mbstring extension is better > [1] & [2]. Do you think that locale is a concern here, and if not, > why? Would it be a good idea to add mb_str_icontains instead? > > If you're going to propose an RFC for this, it would be a good idea to > explain what the real life use case for it is. While str_contains is > very useful for checking the existence of a byte-string within another > byte-string, a case-sensitive check doesn't seem to have much use. > > [1]: https://stackoverflow.com/a/63121809/1839439 > [2]: > https://wiki.php.net/rfc/str_contains#case-insensitivity_and_multibyte_st= rings Thanks for this. In terms of real-life cases, we deal with a lot of datafeeds and user-contributed content. We have lots of rules engines that categorise or display data depending on the content contained (and sometimes these rules change from time to time). So for example, we have a rule that if the string contains the word "exclusive" that it's displayed in a certain way. We can add a rule that says if (str_contains($text, "exclusive"))... and if want to include the ability for sentences to start with the word "Exclusive" we currently have to write like this (as we like functions to be truthy)... stripos(" ".$text, $exclusive) OR str_contains(strtolower($text), "exclusive") I'd just find it useful to have str_icontains/stri_contains available as the same ASCII-folding variant that we have for other functions. --0000000000008e86f206365533a7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, May 29, 2025 at 10:00=E2=80=AFPM = Kamil Tekiela <tekiela246@gmail.= com> wrote:
As I understand, it was a c= onscious decision not to add this function
when str_contains was created. The reason is that case sensitivity is
locale-dependent, and for such use cases, mbstring extension is better
[1] & [2]. Do you think that locale is a concern here, and if not,
why? Would it be a good idea to add mb_str_icontains instead?

If you're going to propose an RFC for this, it would be a good idea to<= br> explain what the real life use case for it is. While str_contains is
very useful for checking the existence of a byte-string within another
byte-string, a case-sensitive check doesn't seem to have much use.

=C2=A0[1]: https://stackoverflow.com/a/63121809/1839439<= /a>
=C2=A0[2]:
https://wik= i.php.net/rfc/str_contains#case-insensitivity_and_multibyte_strings

Thanks for this.=C2=A0

In terms of real-life cases, we deal with a lot of datafeeds and user-con= tributed content.
We have lots of rules engines that categorise o= r display data depending on the content contained (and sometimes these rule= s change from time to time).
So for example, we have a rule that = if the string contains the word "exclusive" that it's display= ed in a certain way.
We can add a rule that says if (str_contains= ($text, "exclusive"))... and if want to include the ability for s= entences=C2=A0to start with the word "Exclusive" we currently hav= e to write like this (as we like functions to be truthy)...=C2=A0 stripos(&= quot; ".$text, $exclusive) OR str_contains(strtolower($text), "ex= clusive")

I'd just find it useful to have= str_icontains/stri_contains available as the same ASCII-folding variant th= at we have for other functions.
--0000000000008e86f206365533a7--