simflex Posted February 1, 2013 Share Posted February 1, 2013 Dear experts, I really, really need your expert assistance. we have an id that when entered into a search box, displays the same id you searched with, if that id is valid and it exists. On the same search box, you can search with a zip code or an address. Issue we have with the id is that it has to follow a certain format for it to produce search results. For instance, if the id has all digits, then a space is to be inserted after the first 2 digits. If has an N or D after the first 2 digits and no additional digits or characters, then no formatting is needed. If it has mostly digits and GG in between the digits, then a space after the first 2 digits as described above and 2 spaces before GG need. If there is N or D after first 2 digits and GG in between the digits, then only 2 spaces before the GG (35D12543 GG125) If the user is searching with zipcode, then we need to recognize that it is zipcode. In other words, if all digits and the digits are less than 6 digits, then it is zip code, no formatting. Now, this is where the real trick comes in. If user is searching by address, how do I modify the code to instruct it NOT to format the address so user can get results? Here is the code that I have so far. The code seems to address the issue of address and zip code but isn't reformatting the ID correctly so that it is reformating ID if ID has ALL digits like 35 1254311235 but it is not reformatting ID if ID has digits with GG in between like 3512543 GG125. There should be a space after 2 digits and 2 spaces before GG the regex for some reason assumes that the GG is the 10th and 11th character and therefore reformats correctly if ID has GG as 10th and 11th character. If the characters don't fall within the 10th and 11th, it doesn't work. Can you please, please take a look at my regex and see what needs fixing? Please forgive me for the long text and thank you very much in advance for your patience and assistance. $patterns = array( '/^(\d\d)(\d{4,})$/', '/^(\d\d[\dDN]\d{6})(GG\d*)$/' ); $replacements = array( '$1 $2', '$1 $2' ); $_GET['id'] = $id; $id = preg_replace( $patterns, $replacements, $_GET['id'] ); Quote Link to comment https://forums.phpfreaks.com/topic/273913-i-am-having-problem-formatting-id/ Share on other sites More sharing options...
Christian F. Posted February 1, 2013 Share Posted February 1, 2013 Have you solved this, and if so what was the solution? I'm sure someone else that has the same problem would appreciate it a lot of you shared your solution. Quote Link to comment https://forums.phpfreaks.com/topic/273913-i-am-having-problem-formatting-id/#findComment-1409609 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.