Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.php Subject: Re: Check for military time Date: Thu, 22 Oct 2015 15:11:42 +0200 Organization: PointedEars Software (PES) Lines: 49 Message-ID: <1874827.QbCUPLQBcH@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1445519503 29560 eJwFwQEBACAIA7BKXvjFOIrQP4IbTVAuF+Vsds5xgLHytM/tjbKs4A2PN4oGCyApw34q3g8TNBCV (22 Oct 2015 13:11:43 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 22 Oct 2015 13:11:43 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYcBwDAIA7CXwrBJzqGM/0+oBKOwwgk6FsvnRWp/B9oEXujOxNJYU71hXnPH80ov9UpmNjSVZxgiP1X8FZ4= Cancel-Lock: sha1:YsQyvkDlFfPLn38Oapmb/k/+Dbw= X-NNTP-Posting-Host: eJwFwYEBACAEBMCVJE8/jsj+I3SH7csrzOGGweRT3FTaWMmAuvo5hScpsQMVjXC2WNiV8z4XXBCG Xref: csiph.com comp.lang.php:15730 Stephan Elinghaus wrote: > Am 2015-10-20 hat Derek Turner geschrieben: >> Is there a quick and dirty way to check that >> >> substr($string, 0 ,3) is a valid military time, ie. 0000-2359? > > Maybe this works for you: > $string="1534"; > if(preg_match("/[012](((?<=2)[0123])|(? echo "is valid"; > else echo "is not valid"; With all such constructs, consider instead: echo ($boolean) ? $ifTrue : $ifFalse; This is particularly useful if you can use “” to just output the (string representation of) the result of an expression. > ?> Avoid ending PHP files with that; you may be accidentally outputting trailing whitespace otherwise. -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.