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); ?> Link to comment https://forums.phpfreaks.com/topic/177678-preg_replace-part-of-string/ 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); Link to comment https://forums.phpfreaks.com/topic/177678-preg_replace-part-of-string/#findComment-937077 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); Link to comment https://forums.phpfreaks.com/topic/177678-preg_replace-part-of-string/#findComment-937088 Share on other sites More sharing options...
cags Posted October 14, 2009 Share Posted October 14, 2009 Oh yer, good point Link to comment https://forums.phpfreaks.com/topic/177678-preg_replace-part-of-string/#findComment-937090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.