Jump to content

Recommended Posts

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

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);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.