Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125382 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 qa.php.net (Postfix) with ESMTPS id 9BD251A00BD for ; Mon, 2 Sep 2024 11:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725275985; bh=MRmhgy1bott1n/Gc4zpXB0lQF4tjaGmEoGysSnh3fvE=; h=From:Date:Subject:To:From; b=PArScrYbFrT/5s6EB6bTVIeG5zWnoSdS4gFtSBZylSCRfWoY7XSrVGi7wAyzfuctP VsQIbTh1CJXfyE4/FO2pPbv7tmAlcaKXPJapNqBN+mrZoiAxz7dAEJrB8moaG040NA IYv8bdP0OiFb3rwOfHSf1V4+ESIcjGEtjqbj73H6Vgqa2BdQYBuijvvO+MJMP0SFff nRi8ZmAMRMiX4aFBTdLJe4Pn24lJoS3w/TTRSCl0q6u5xTUp2FSWSk8oeIkYEAvxTT z3o9dHR2Re6MqUW+zfOykT20s6PJ3m4R5zWOo83NMoEdpyZF0H9H+b2+ucYlpSZNLV Al7vsXYK5vJ/Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6CF9C180072 for ; Mon, 2 Sep 2024 11:19:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 ; Mon, 2 Sep 2024 11:19:45 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7163489149eso2746560a12.1 for ; Mon, 02 Sep 2024 04:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725275867; x=1725880667; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=MRmhgy1bott1n/Gc4zpXB0lQF4tjaGmEoGysSnh3fvE=; b=BLox6PMWKAfKnMECBX8Ui27zuCY2/2tWEuvVlyTZDP7gGJRk9fM0+19e0w1YF8KIPT 9z7IhWpsJ6Uo3chSG4vgOL0tusPfwhZTPEtIwN+fkab4QEqsQne1HmA6uDaWVP2xr36T wR1HNdo0zvsbx5Y0GMQt2e9AOFctkvH43qHxaOcFuicjxjeGUUFiszGY9vL4e8IksviT 0SdT7O0ioYvSpMeXUTYGrqbMX8zf+IZTg0qf0w2IDf1jL36CeCzPDpqY5882cJLKmGAI 0tHRBD1/1taOmkyP/s15vFApDhGn3944wN9n2qN5lI+EN7t3ob0jLbGSQC2GgtMtizvF n8Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725275867; x=1725880667; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MRmhgy1bott1n/Gc4zpXB0lQF4tjaGmEoGysSnh3fvE=; b=g2aO8/n5Qhj6TlBxMfu74A9XmnnVTH4oa+0iG11KSAzj3EZXM+jirXMbfZ9hz1ZIcE 2sRYG8LXy4vo8h81NMamn7kx0Q2xG4/TPuutJP9i9dvbFFalMqqebqEXhHc09ySWejyr MBK+nf+N7uglnrDWQYMPnsrN6l50KrtGStMyBrqwtxgBYZB45rZeczni8ILM+x8L17cm 3XN5/mGHGa3v5U7bhFOGrxlqZDoVfkt+T1bNJvu51ERl+xqeSLb7bxKSXVOZCe9L6PUY oj560HUbW72B+U1X4PXJz6cvy8kzULHvd+ojqAoIRramsKSrpmpCfn38j7XlMr0IxFsI IlyQ== X-Gm-Message-State: AOJu0YxcOoMRlBfCdvxyHjei4e1Suj8HVm2L0O3IVNgyyQSFCIhb3pB9 JbZ5R1L9wQmr4vREgDhJe6Rd/XWts7m4FwtOZ/HtJKl9HbU5UzilmhNeWVoMgMnwtBRxzmPBkn7 8978G2y0YQmQyps5jIRGyrjdLG6ctB5SZ X-Google-Smtp-Source: AGHT+IFnVgASF8FzCXiulsCfg57yU6GH7Kbd5M2JsxiIS8wHQQ28PqvMDc7mLTW3Ekr59WnALY1lWVqM8GjgjsyLFcU= X-Received: by 2002:a17:903:228a:b0:202:cf5:1014 with SMTP id d9443c01a7336-2058417b228mr22631695ad.4.1725275867010; Mon, 02 Sep 2024 04:17:47 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 2 Sep 2024 13:17:35 +0200 Message-ID: Subject: [PHP-DEV] strrchr with needle with multiple characters To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000315e7406212117e7" From: misterdeviling@gmail.com (Vincent Langlet) --000000000000315e7406212117e7 Content-Type: text/plain; charset="UTF-8" I was today old when I discovered the big difference between strchr and strrchr in the way they handle needle with multiple characters. It's explained in the doc https://www.php.net/manual/en/function.strrchr.php - If needle contains more than one character, only the first is used. This behavior is different from that of strstr() . You can see an example https://3v4l.org/7j5ab I feel like this behavior has no benefit (if I want to look for the first character, I can pass `substr($needle, 0, 1)` instead) and is just error-prone. Is there a reason for such behavior ? Would it be easy to change it (I have no knowledge at all in C and in the existing PHP code) ? --000000000000315e7406212117e7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I was today old when I discovered the big difference betwe= en strchr and strrchr in the way they handle needle with multiple character= s.

It's explained in the doc=C2=A0https://www.php.net/manual/en/function.str= rchr.php
-=C2=A0If=C2=A0needle=C2= =A0contains more than one character, only the first is used. This behavior = is different from that of=C2=A0strstr().

You can see an example=C2= =A0https://3v4l.org/7j5ab

I f= eel like this behavior has no benefit (if I want to look for the first char= acter, I can pass `substr($needle, 0, 1)` instead) and is just error-prone.=

Is there a reason for such behavior ? Would it be easy to change it= (I have no knowledge at all in C and in the existing PHP code) ?
--000000000000315e7406212117e7--