Do I need a regular expression?

Discussion in 'PHP' started by absentx, Apr 11, 2011.

  1. #1
    I have some data that I am putting in a database but I need it modified as it gets inserted.

    I have several entries that have two digit years in parentheses. They come in the following formats:

    (98) OR (87-92)

    I basically want to rewrite them like this:

    (1998) OR (1987-1992)

    And I also need to check for the condition of a number between 00 and 11 because that would then constitue appending 20 to the beginning rather than 19.

    Can anyone help me get started with this?
     
    absentx, Apr 11, 2011 IP
  2. Sepehr

    Sepehr Peon

    Messages:
    568
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this:

    
    <?php
    
    $pattern = array('/\b[23456789]\d\b/', '/\b0\d\b/', '/\b[1][0123456789]\b/'); 
    $replace = array( '19$0', '20$0', '20$0'); 
    $subject = array('94', '11', '03-10', '55', '70-84', '12', '19', '07-14'); 
    
    var_dump((preg_filter($pattern, $replace, $subject))); 
    
    ?>
    
    PHP:
     
    Sepehr, Apr 11, 2011 IP
  3. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That worked perfectly and did exactly what I needed. Thank you very much!
     
    absentx, Apr 18, 2011 IP