Jump to content

preg_replace part of string


ejaboneta

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
Share on other sites

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.