Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51765 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89516 invoked from network); 31 Mar 2011 14:49:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Mar 2011 14:49:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=martin@divbyzero.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=martin@divbyzero.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain divbyzero.net from 87.230.111.147 cause and error) X-PHP-List-Original-Sender: martin@divbyzero.net X-Host-Fingerprint: 87.230.111.147 mx.bauer-kirch.de Linux 2.6 Received: from [87.230.111.147] ([87.230.111.147:39899] helo=mx.bauer-kirch.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/13-04048-494949D4 for ; Thu, 31 Mar 2011 09:49:58 -0500 Received: by mx.bauer-kirch.de with ESMTP id 1Q5JC3-0002J9-VU; Thu, 31 Mar 2011 16:49:52 +0200 Message-ID: <4D94948E.5000901@divbyzero.net> Date: Thu, 31 Mar 2011 16:49:50 +0200 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: Philip Olson CC: Dan Birken , internals@lists.php.net References: <4D92CC38.5040900@toolpark.com> <004301cbeee8$e54a8280$afdf8780$@com> <4D9387BE.4030808@divbyzero.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Adding a more logical string slicing function to PHP From: martin@divbyzero.net (Martin Jansen) On 31.03.11 16:41, Philip Olson wrote: > On Mar 30, 2011, at 1:42 PM, Martin Jansen wrote: >> Both str_startswith and str_endswith have been suggested in the past: >> >> http://marc.info/?t=121647230100001&r=1&w=2 >> >> I recently got around to merge them into a largely unfinished extension >> so they are archived somewhere safe: https://github.com/mj/php-ext-str > > I see str_contains() on the TODO there. I've always wanted in_string() so am glad to see a similar item. Using strpos() for this task feels dirty, much like using arrpos() for arrays would ;) >From time to time I have wondered if it made sense to add a new operator "in" that works on variables of different type and could replace in_string/str_contains: if ("a" in "abc") { ... } if ("a" in array("a", "b", "c")) { ... } if ("a" in $obj) { /* true if $obj->__contains("a") returned true */ } I suspect there is a massive potential for WTF issues in there and that most people would hate this feature. Which is why I am only thinking out loud here -- I have zero intentions to suggest this as a future enhancement for PHP. ;-) - Martin