ejaboneta Posted October 14, 2009 Share Posted October 14, 2009 I'm trying to fix a bunch of formatting errors that resulted in 1900 dates being converted into 2000 dates... I'm trying to change 12/20/2012 to 12/20/1912. I can replace any /20 with /19 but I dont any days to be mixed up and being changed from 12/20/2012 to 12/19/1912. I tried doing "/20.{2}$" but of course it I'll end up with 12/20/19. Sorry I'm new to regex so I am pretty lost. <?php $data = '12/20/2012'; $birthstr = "/\/20/"; $birthrep = '/19'; $birthday = preg_replace($birthstr,$birthrep,$data); ?> Quote Link to comment Share on other sites More sharing options...
cags Posted October 14, 2009 Share Posted October 14, 2009 Probably not the best solution, but it's late, so off the top of my head.... preg_replace("~(\d\d/\d\d)/20(\d\d)~", "$1"."/19"."$2", $input); Quote Link to comment Share on other sites More sharing options...
.josh Posted October 14, 2009 Share Posted October 14, 2009 Probably not the best solution, but it's late, so off the top of my head.... preg_replace("~(\d\d/\d\d)/20(\d\d)~", "$1"."/19"."$2", $input); you don't need those first 4 \d's since your pattern is expecting the 2 \d's after the 20. $input = preg_replace("~/20(\d\d)~", "/19$1", $input); Quote Link to comment Share on other sites More sharing options...
cags Posted October 14, 2009 Share Posted October 14, 2009 Oh yer, good point Quote Link to comment 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.