HaxorNab Posted December 10, 2016 Share Posted December 10, 2016 (edited) Hi, I have a problem. I am doing one little job with php and html.In html i have textbox in which person id must be entered (11 numbers) I need to do with php that when all 11 numbers are entered, date of birth and gender need to be shown,For example:if id is : 39310121111 first number stands for mele/female (if 3 mele if 4 female) all next numbers are date of birth 1993 10 12 (last 4 numbers doesnt have meaning)Basicly question is. how to make syntax that entered id will be shown as gender and date of birth ? can't think of any ideas. new at php. Edited December 10, 2016 by HaxorNab Quote Link to comment https://forums.phpfreaks.com/topic/302709-showing-mele-or-female-and-brith-date-from-entered-personal-id-number/ Share on other sites More sharing options...
requinix Posted December 10, 2016 Share Posted December 10, 2016 Take a look at substr. Write some code and if you have problems then come back and post what you have and a description about what is happening. Quote Link to comment https://forums.phpfreaks.com/topic/302709-showing-mele-or-female-and-brith-date-from-entered-personal-id-number/#findComment-1540183 Share on other sites More sharing options...
Jacques1 Posted December 10, 2016 Share Posted December 10, 2016 You should actually combine the data extraction with validation. Always expect to get wrong input. Regular expressions can help you: '/\\A(?<gender>3|4)(?<dob>\\d{6})\\d{4}\\z/' Read: A 3 or 4 followed by 6 digits for the date of birth followed by another 4 digits. You can then easily extract the ID parts: <?php const ID_PATTERN = '/\\A(?<gender>3|4)(?<dob>\\d{6})\\d{4}\\z/'; $input = '39310121111'; // validate the input and simultaneously extract the parts $idParts = null; if (!preg_match(ID_PATTERN, $input, $idParts)) { die('Invalid input. Please enter a valid 11-digit ID.'); } // the individual parts var_dump($idParts['gender'], $idParts['dob']); Storing the year of birth as two digits isn't very smart, because now you need extra logic to distinguish between 19xx and 20xx. Let's not repeat the 2K problem. Quote Link to comment https://forums.phpfreaks.com/topic/302709-showing-mele-or-female-and-brith-date-from-entered-personal-id-number/#findComment-1540184 Share on other sites More sharing options...
HaxorNab Posted December 11, 2016 Author Share Posted December 11, 2016 Thanks for reply guys, gonna try it right away Quote Link to comment https://forums.phpfreaks.com/topic/302709-showing-mele-or-female-and-brith-date-from-entered-personal-id-number/#findComment-1540203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.