Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39106 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16328 invoked from network); 20 Jul 2008 00:37:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2008 00:37:02 -0000 Authentication-Results: pb1.pair.com header.from=lstrojny@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lstrojny@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 78.46.69.2 as permitted sender) X-PHP-List-Original-Sender: lstrojny@php.net X-Host-Fingerprint: 78.46.69.2 milch.schokokeks.org Received: from [78.46.69.2] ([78.46.69.2:52239] helo=milch.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/19-13864-DA882884 for ; Sat, 19 Jul 2008 20:37:02 -0400 Received: from [192.168.0.102] (xdsl-87-78-212-100.netcologne.de [::ffff:87.78.212.100]) (AUTH: PLAIN lars@schokokeks.org, TLS: TLSv1/SSLv3,256bits,CAMELLIA256-SHA) by milch.schokokeks.org with esmtp; Sun, 20 Jul 2008 02:36:57 +0200 id 000000000000C007.00000000488288AA.00007A21 To: Martin Jansen Cc: internals In-Reply-To: References: Date: Sun, 20 Jul 2008 02:36:57 +0200 Message-ID: <1216514217.11114.6.camel@localhost> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=_milch.schokokeks.org-31265-1216514218-0001-2" X-Mailer: Evolution 2.22.2 Subject: Re: [PHP-DEV] New string functions: str_startswith() and str_endswith() From: lstrojny@php.net (Lars Strojny) --=_milch.schokokeks.org-31265-1216514218-0001-2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Martin, first of all, thanks for you work! A few comments below. Am Samstag, den 19.07.2008, 14:55 +0200 schrieb Martin Jansen: > Attached you'll find a patch against PHP_5_3 that implements two new > string functions: >=20 > str_startswith(haystack, needle [, case_sensitivity]) That's in my opinion too easy to solve with strpos($haystack, $needle) =3D=3D=3D 0. > checks if haystack starts with needle. The check is performed > case-insensitively, but this can be overridden by passing TRUE as the > value for the third parameter. The second function >=20 > str_endswith(haystack, needle [, case_sensitivity]) [...] Suffix checking is indeed a bit harder. But I'm not sure if we should introduce a function for every special case. Suffix verification often is about verifying file extensions. That could be easily solved with pathinfo() (and to make that easier, it would be more helpful to allow the engine to directly access returned arrays like pathinfo($file)['extension']). The other thing I would love to see is something I really love in Ruby: you have various ways to work with substrings[1]. For example you can do "foobar"[-3,3] =3D=3D "bar" to check the suffix. That's in my opinion much easier and flexible. So -1 from me for the new string functions, but +1 for niftier variants to work with offsets. [1] =EF=BB=BFhttp://pleac.sourceforge.net/pleac_ruby/strings.html cu, Lars --=_milch.schokokeks.org-31265-1216514218-0001-2 Content-Type: application/pgp-signature; name="signature.asc" Content-Transfer-Encoding: 7bit Content-Description: Dies ist ein digital signierter Nachrichtenteil -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (GNU/Linux) iQIcBAABAgAGBQJIgoioAAoJECQPF+sCY6wHQEsP/iAHtDX79jyYhm68pvEzOdk2 oJurHJmIDQwF32G/zx7Llq4j9zDPy1C4m98wlkpu0VnurgTFpaDRo6AIbeQiGfDh ZIhuXD/JAqHZa5aAEnGZN/OiDgXBKrd4d86ht3t8NPWHM58p9vOjHJNFko/gCbv5 6HMRktZXLSQXCcFf2f86LzgwHgVKKRZv0rSfuRK8KcFS1U4mBIzALMYsX+PmxMDz C7zP3Y/t4tznELv5Xt43bmeGce0Ee9TnrLBjIJ9JxOX6cYuLHuZ9N6wDgeNJ/c9t pnobamlgkNWx1i9rhd8MNm7D4J6PMb83/WtkKiASTGJoSAS40n3qFyzNvQEXH9C1 QYE4TwBOrtssDWon5z1s/fLU5n3j38/eBFSd3PBnZ5TAfIBJezu1yjvCDCB7S3v3 3N/mqG3VF/snut7o+IHXClrqGRyKLVVfEoNouwi3JCVZQkSpowdrDx3wIVNOVE/S 2LnrvkBTx39WYUlGvXfiByov9G7wN5vTJSZG79z2RaRy19E7I/PiKA/GAvU4AiJk oHlJqZ8o3fTzO6q1RfSemu3Dssku652M24dfsjoq/uvuxgIE6K0JfLHdSK50us9Z C57TOTWbWepMwC1o/kB1LSCvMjTzcfeVxyyd+ZXLp080H6vmwrzq3odO6nggxToO leswdHD1/PiBF65+34Xw =8xcC -----END PGP SIGNATURE----- --=_milch.schokokeks.org-31265-1216514218-0001-2--