note 121936 added to function.strtotime

From: Date: Wed, 29 Nov 2017 07:25:17 +0000
Subject: note 121936 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-209244@lists.php.net to get a copy of this message
In some countries I noticed that people storing in database strings like 20h or 20u what is equal to 20:00 and 21h30 or 21u30 what is equal to 21:30. strtotime() not understand that string and comparing or time modulation can be tricky. Because of that I wrote one good solution for it: <?php function bo_strtotime($string) { if(preg_match('/([0-9]+)[uh]{1}/i',$string)) { $string = preg_replace(array('/[uh]/i','/:(?![0-9]+)/'), array(':',':00'), $string); } return strtotime($string); } ?> This small function acts same like strtotime() only it accept 20u and 20h and convert into normal time, after that in normal unix timestamp. ---- Server IP: 208.43.231.9 Probable Submitter: 78.30.154.70 ---- Manual Page -- http://php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/121936 Del: integrated -- https://master.php.net/note/delete/121936/integrated Del: useless -- https://master.php.net/note/delete/121936/useless Del: bad code -- https://master.php.net/note/delete/121936/bad+code Del: spam -- https://master.php.net/note/delete/121936/spam Del: non-english -- https://master.php.net/note/delete/121936/non-english Del: in docs -- https://master.php.net/note/delete/121936/in+docs Del: other reasons-- https://master.php.net/note/delete/121936 Reject -- https://master.php.net/note/reject/121936 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209244) next »