Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64338 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62024 invoked from network); 18 Dec 2012 12:16:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Dec 2012 12:16:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=leight@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leight@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.173 as permitted sender) X-PHP-List-Original-Sender: leight@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-ie0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:35699] helo=mail-ie0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/18-33799-98E50D05 for ; Tue, 18 Dec 2012 07:16:10 -0500 Received: by mail-ie0-f173.google.com with SMTP id e13so713281iej.32 for ; Tue, 18 Dec 2012 04:16:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Wm4ArVbDbko3/h5Lx85LnbJ2At2xmXWazaV09UyvK5g=; b=E2BDykG+bZgUXBTCE+NY1adAOMEksdxnORHgvC+AWW6kZ1VqQxkKYfPNmXCyGrK5j5 UcT1z/dKxav+VkE7mTLp4bOmqwLgzeyI0IXj9cSwuwoi6vYFsoYzoYZk7SmH2MQ3zNjb 5Ityrpki1B4LKprEoMHG0gBz6YmMGwcEJW1Vl5rJeDca06o80G/oWtD5YMaOEzjE+B1C UVqW7ICfnV/5G3daAEjugnOYVTgklYJV3m2GfLWRtUZ9nqrqdGMV0D8OplRmnHgKzc2q ygOtqlLEUABnBugRlDO4C2GJXUV0o/SXQ2W6BSrT5JMPTwpdIeE8YRHAQ0uBgjQQO6Pr OSpw== MIME-Version: 1.0 Received: by 10.42.215.10 with SMTP id hc10mr1723944icb.19.1355832966207; Tue, 18 Dec 2012 04:16:06 -0800 (PST) Received: by 10.64.68.81 with HTTP; Tue, 18 Dec 2012 04:16:06 -0800 (PST) In-Reply-To: <50D05CD0.8080206@php.net> References: <50D05CD0.8080206@php.net> Date: Tue, 18 Dec 2012 12:16:06 +0000 Message-ID: To: Stefan Neufeind Cc: php-dev Content-Type: multipart/alternative; boundary=20cf301d3a8c53593804d11f7673 Subject: Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays From: leight@gmail.com (Leigh) --20cf301d3a8c53593804d11f7673 Content-Type: text/plain; charset=ISO-8859-1 Both str_replace and preg_replace already support some array based replacements, I think adding more options to these functions specifically would just lead to confusion. What you're proposing can already be achieved quite easily with preg_replace_callback and passing your array/options into the anonymous function with `use`, I'd personally welcome a str_replace_callback counterpart. On 18 December 2012 12:08, Stefan Neufeind wrote: > Hi, > > inside a framework-/scripting-project we've lately discussed > string-replacements with arrays. > > Currently PHP supports either replacing one string by another or > replacing first element from one array with first from another array. > > What I'd like to propose is for str_replace and preg_replace to introduce: > * a functionality to replace one string with strings from an array > * to (optionally) allow for rolling replacements (1,2,3, 1,2,3, ...) > * to (optionally) allow to skip strings already replaced > (that means not to accidentially double-replace strings) > > This would allow to do things like > > $content = str_replace('
  • ', > array('
  • ', '
  • ', '
  • '), > $content); > > optionally starting over from A again. (Current default is to stop when > there are no more elements to replace with). > > > Would such a change/extension find support? > > > Kind regards, > Stefan Neufeind > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf301d3a8c53593804d11f7673--