Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49572 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46548 invoked from network); 5 Sep 2010 13:06:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2010 13:06:51 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 unknown Solaris 10 (beta) Received: from [217.114.211.66] ([217.114.211.66:55683] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/77-52399-FD5938C4 for ; Sun, 05 Sep 2010 09:06:40 -0400 Received: from [192.168.1.29] (ppp-93-104-111-176.dynamic.mnet-online.de [93.104.111.176]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id B275A44A19; Sun, 5 Sep 2010 15:06:36 +0200 (CEST) To: Alex Baumann Cc: internals@lists.php.net In-Reply-To: <9A.BD.52399.493A28C4@pb1.pair.com> References: <9A.BD.52399.493A28C4@pb1.pair.com> Content-Type: text/plain; charset="UTF-8" Date: Sun, 05 Sep 2010 15:06:31 +0200 Message-ID: <1283691991.2190.2.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.2 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Built-in function: between From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Sat, 2010-09-04 at 21:52 +0200, Alex Baumann wrote: > Hi! > Since I'm using this function in each project I'm working on, how about > making it a built-in function? > > function between ($text, $between, $and) { > $start = strpos($text, $between)+strlen($between); > if ($start === false) return ""; > $end = strpos($text, $and, $start); > if ($end === false) return ""; > return substr($text, $start, $end-$start); > } > > Basicly this function returns a substring given in a text $text between > two strings, $between and $and, occuring in $text. > > Here are some examples: > echo between("PHP is awesome!", "PHP ", " awesome!"); > > is > echo between("PHP is awesome!", "P", "o"); > > HP is awes > echo between("PHP is awesome!", "PHP ", "great!"); > > preg_match('/PHP (.*) swesome/', 'PHP is awesome', $matches); works nicely, we won't add special purpose functions for things that can easily be done already. > As mentioned above, this function is very useful, for example when > parsing formated input data like html files, and everyone I told about > it adopted it and is very thankful. For parsing DOM or tidy are better. johannes