Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114577 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15493 invoked from network); 25 May 2021 10:06:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 May 2021 10:06:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9C8BD1804D8 for ; Tue, 25 May 2021 03:18:13 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 25 May 2021 03:18:13 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id p20so37395802ljj.8 for ; Tue, 25 May 2021 03:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AGGX5RsIniI7UApLCOUzA61IlLx/4btAmDGQJU8vmc0=; b=naa8p5YwkoF7ZwwJSYKO5BKqHmdYBpLpZQW9np6XmjOr44oWa8lbKGbGO43mBi00Mc dpCcDb3pPXWhfQYcYxD4Fu7zSfSXLUAs0Efu17wz24NbMh5k47BIJKLpW3Z46XucQQjx D9z2Z/obVuLsq2Ir4l1uQp450mTc9e19an27nmiLC1L11F96a13kFJ0NnVgTiFadtSnF B4a6H7ZtnCb3yNbodocmGMsQLQmgkTbXIsUrkRqpJynHq238VLhtpC/Xj9hrfrTcy7wJ Im6OCryK1xNwd9dRV7BKLSDwBmDTGV6VZPlnCDgVqWeSQoEWyd7gUVKyTqv81upH3TNJ ZIMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AGGX5RsIniI7UApLCOUzA61IlLx/4btAmDGQJU8vmc0=; b=nWCtruHrQr9F5xK1NncnAmlzP90BIIl5mpXGM4Iu8gkVkkUqqcbR0NyE5ArsFe0iIh VMVJjthNckcVDfYIg5FGqPzDA+zfdVOlYogCDaOyGn1xZFmc+d6pswe9Xds/W8RSwwyU R2BEgTn7tWRlE/42+QahM28FvVrp8EYT6XAaac+uOcNLyUJZi7kdtc0NxCOW4Db8FeyJ Zs+AapM8hVlyQu1/rert7sLP08uIIEvm9hteUPKvjft9s/tbMHQvSSmKHy4DRYr3OCSL DPUlcontlXrcgCJBkrNClHA3buzjyXf+C70GGSlBwyu6r4EhCctyeV0XjBOek0f79HO1 RFtw== X-Gm-Message-State: AOAM530EI1bsRMhVdVTTDW9IOPlJrsrDWQsJx5pRB/GuqPFUukF10ymW Oe26tHYUAQLTTWMDtJeU15iBfbbMrS/BfcWCP+w= X-Google-Smtp-Source: ABdhPJwmTiYMQ6xhE14pAe5kVB2ekjNYIlBr1nO0MV526KzQExDai1ln5OphAp3KErE9V1CiNoGJdy9V4nS9MtdVOlU= X-Received: by 2002:a2e:9189:: with SMTP id f9mr21345154ljg.353.1621937890532; Tue, 25 May 2021 03:18:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 25 May 2021 12:17:54 +0200 Message-ID: To: Eugene Sidelnyk Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000d0218605c324d7c0" Subject: Re: [PHP-DEV] Bug with str_replace From: nikita.ppv@gmail.com (Nikita Popov) --000000000000d0218605c324d7c0 Content-Type: text/plain; charset="UTF-8" On Tue, May 25, 2021 at 12:13 PM Eugene Sidelnyk wrote: > When use str_replace with arrays there's strange behavior > > https://3v4l.org/maNqa > > > ```php > var_dump(str_replace( > [ > ',', > '.', > ],[ > '.', > ',', > ], > '1.2,3' > )); > ``` > > This code is expected to replace all commas with dots and all dots with > commas, however in result we get all commas. > str_replace() performs the first replacement on the whole string, then the second replacement on the whole string etc. If you want to replace all strings "in parallel" you need to use strtr() instead: https://3v4l.org/tk6FO I believe this is what the "Caution" on http://php.net/str_replace is trying to tell you, though its phrasing is rather confusing. Regards, Nikita --000000000000d0218605c324d7c0--