+ Reply to Thread
Results 1 to 2 of 2

Thread: Regular Expression

  1. #1

    Regular Expression

    I have a regular expression that looks like this:
    Code:
    $pattern = '#post/date/(\d\d\d\d)-(\d\d)-(\d\d)#';
    And, I have a string that matches it:
    Code:
    $string = 'post/date/2012-01-01';
    I need to end up with an array that looks like this:
    Code:
    $groups = array('2012', '01', '01);
    The array should contain the parts of the string that matched the three regular expression groups that are within parentheses. can you help me with that?

  2. #2
    This is not a Regular Expression but it will solve your issue :
    Code:
    <?php
    $string = 'post/date/2012-01-11';
    $date= basename($string);
    $array=explode('-',$date);
    print_r($array);
    ?>
    The output array will look like this :
    Code:
    Array
    (
        [0] => 2012
        [1] => 01
        [2] => 11
    )

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts