Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7324
| Date | 2012-10-14 21:28 +0200 |
|---|---|
| From | Luuk <luuk@invalid.lan> |
| Newsgroups | comp.lang.php |
| Subject | Re: Verifying time in php |
| References | <slrnk7l2e1.3f9.houghi@penne.houghi> |
| Message-ID | <hcgrk9-b4b.ln1@luuk.invalid.lan> (permalink) |
On 14-10-2012 11:45, houghi wrote:
> I have a form that has the following entry fields:
> hours
> minutes
> seconds
>
> I need the time in seconds and that works:
> $realtime=$_POST['hours']*3600+$_POST['minutes']*60+$_POST['seconds'];
>
> However people can fill out nothing or they could enter characters
>
> What is the easiest way to verify if what the people filled out is
> correct? I have tried, but I get lost in the if statements.
>
> Extra difficult is that they must not fill out all three. Only one is
> enough. e.g.
> 1 hour and no minutes or second gives 3600
> 1 hour, 1 minute and 1 second gives 3661
> 1 hour and 'X' should give an error.
> All empty should give an error
> empty hour 70 minutes and 75 seconds gives 4275.
> Hours of more then 24 will be possible as well.
> I might even add number of days.
>
> If the last one gives an error, but it makes the life much easier, I can
> live with that
>
> It is the fact that they do not need to fill out all three that I am
> stuck.
>
> What I have tried is first to see if all are empty
> Next try to see if each one is not a number
> Then I need to figure out if there is a combination of some of it.
>
> And that is when I get lost in the if statements and loops in loops.
>
> I am sure there is an easy way to tell if all is nice and works well,
> but how? Seaching google gave me transfering from seconds to H:i:s, but
> that is not what I want.
>
> houghi
>
whats wrong with this code:
<?php
$h=13;
$m=14;
$s=15;
$t=sprintf("%02d:%02d:%02d", $h, $m, $s);
$x=strtotime($t);
print $x."\n";
print date("l dS F Y H:i:s ",$x)."\n";
You only need some more validation on the 'strtotime' and 'date'
functions.....
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 11:45 +0200
Re: Verifying time in php Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-14 10:25 +0000
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 13:50 +0200
Re: Verifying time in php Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-14 21:12 +0000
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 12:30 +0200
Re: Verifying time in php "J.O. Aho" <user@example.net> - 2012-10-14 15:03 +0200
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 17:16 +0200
Re: Verifying time in php Michael Fesser <netizen@gmx.de> - 2012-10-14 17:50 +0200
Re: Verifying time in php "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-10-14 18:22 +0200
Re: Verifying time in php "Peter H. Coffin" <hellsop@ninehells.com> - 2012-10-14 11:41 -0500
Re: Verifying time in php Martin Leese <please@see.Web.for.e-mail.INVALID> - 2012-10-14 11:06 -0600
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 19:41 +0200
Re: Verifying time in php Michael Fesser <netizen@gmx.de> - 2012-10-14 21:03 +0200
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 22:39 +0200
Re: Verifying time in php Christoph Becker <cmbecker69@gmx.de> - 2012-10-14 17:52 +0200
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 19:20 +0200
Re: Verifying time in php "J.O. Aho" <user@example.net> - 2012-10-14 20:41 +0200
Re: Verifying time in php Christoph Becker <cmbecker69@gmx.de> - 2012-10-14 20:49 +0200
Re: Verifying time in php houghi <houghi@houghi.org.invalid> - 2012-10-14 22:32 +0200
Re: Verifying time in php Richard Damon <news.x.richarddamon@xoxy.net> - 2012-10-14 11:44 -0400
Re: Verifying time in php Luuk <luuk@invalid.lan> - 2012-10-14 21:28 +0200
csiph-web