Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95296 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22814 invoked from network); 18 Aug 2016 15:29:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2016 15:29:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.230 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.230 mail4-3.serversure.net Linux 2.6 Received: from [217.147.176.230] ([217.147.176.230:45016] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/80-17996-164D5B75 for ; Thu, 18 Aug 2016 11:29:38 -0400 Received: (qmail 22340 invoked by uid 89); 18 Aug 2016 15:29:34 -0000 Received: by simscan 1.3.1 ppid: 22334, pid: 22337, t: 0.0784s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.7?) (lester@rainbowdigitalmedia.org.uk@81.138.11.136) by mail4.serversure.net with ESMTPA; 18 Aug 2016 15:29:34 -0000 To: internals@lists.php.net References: <8442f1fa5544b2ca03e7cebbc64e8e5c@wkhudgins.info> <9ab63bd0-af85-29ec-8de3-1f212c54b954@lsces.co.uk> <6ce96cbb-fbf7-fe18-a43a-cafed7f21f7c@gmail.com> Message-ID: <2a4f5187-3a40-8778-23dc-d5cec5b497a5@lsces.co.uk> Date: Thu, 18 Aug 2016 16:29:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <6ce96cbb-fbf7-fe18-a43a-cafed7f21f7c@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC Posted for str_begins and str_ends functions From: lester@lsces.co.uk (Lester Caine) On 18/08/16 12:39, Rowan Collins wrote: >> Is starting just a Firebird SQL thing or is it more generally available. >> I do a few google searches but as usual when searching for things like >> 'starting' one gets hundreds of pages on 'running' the software and it's >> other connotations. > > I've never come across it in Postgres, MS SQL Server, or MySQL. > Generally LIKE 'abc%' is the recommended approach (and will I think hit > the index in many cases, because the DBMS can optimize the case of a > prefix match if it knows at planning time). A "starting" keyword would > certainly be useful if it was there. :) > > It doesn't quite fill the same need as a PHP function, of course, > because you might be checking user input, or API results, or all sorts > of things that won't, or haven't yet, hit the database. Currently the > common idiom for that is the ugly strpos($string, 'abc') === 0 PHP is never going to be loading millions of records into memory and searching them. That is the job of a database, and while LIKE 'abc%' can be optimised to use an index and speed up results, if the 'abc%' is supplied as a parameter that is not generally possible to prepare the query using an index. While STARTING always knows the matching string is the first characters of the index. While PHP and SQL share a number of alternatives, the SQL versions will have a premium on search time if an index can't be used. I was just wondering if str_starting and str_ending matched better with other string handling options. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk