Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49571 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42039 invoked from network); 5 Sep 2010 12:45:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2010 12:45:08 -0000 Received: from [127.0.0.1] ([127.0.0.1:1444]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 8C/96-52399-3D0938C4 for ; Sun, 05 Sep 2010 08:45:07 -0400 X-Host-Fingerprint: 95.222.111.182 ip-95-222-111-182.unitymediagroup.de Received: from [95.222.111.182] ([95.222.111.182:17386] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/BD-52399-493A28C4 for ; Sat, 04 Sep 2010 15:52:53 -0400 Message-ID: <9A.BD.52399.493A28C4@pb1.pair.com> To: internals@lists.php.net Date: Sat, 04 Sep 2010 21:52:49 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 95.222.111.182 Subject: Built-in function: between From: php@ikgcom.de (Alex Baumann) 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!"); > 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. Thanks, Alex