Re: If the first four characters are "0000", then do {}

From: Date: Tue, 26 Jan 2010 04:31:56 +0000
Subject: Re: If the first four characters are "0000", then do {}
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-301460@lists.php.net to get a copy of this message
On Mon, Jan 25, 2010 at 08:12:43PM -0800, Daevid Vincent wrote: > > -----Original Message----- > > From: Paul M Foster [mailto:paulf@quillandmouse.com] > > Sent: Monday, January 25, 2010 8:05 PM > > To: php-general@lists.php.net > > Subject: Re: [PHP] If the first four characters are "0000", then do {} > > > > On Mon, Jan 25, 2010 at 09:36:50PM -0500, John Taylor-Johnston wrote: > > > > > I am reading the manual: dñË]=ƒ‰šù > > > «z4¡http://ca.php.net/manual/en/ref.strings.php > > > > > > $mydata->restored = "0000-00-00"; > > > > > > How do I express this? If the first four characters are > > "0000", then do {} > > > > > > What I am looking for is in strpos(), no? > > > > > > if (????????????) > > > { > > > } > > > > >From what I understand, strpos() faster than a lot of other similar > > string functions and much faster than regexps. You could do: > > > > if (strpos($mydata->restored, '0000') === 0) { > > do_stuff(); > > } > > Ah. Clever use of the "== 0" (tripple equals not necessary). No, the === was purposeful, since strpos can return false if there's no match. If you simply use == 0, it will trigger on both false, and the 0 index. If you use !== false, you're only testing for no match. Paul -- Paul M. Foster

« previous php.general (#301460) next »