unknown value quick question

Discussion in 'PHP' started by jonny2210, Jun 26, 2007.

  1. #1
    I need to remove (Year-Month-Day) from a string without knowing the values of (year-month-day).

    so what do i do to tell it that those are unknown values.
     
    jonny2210, Jun 26, 2007 IP
  2. Datawalke

    Datawalke Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can I see an example of the string?

    If formatted correctly and at the front of a string an easy way is:
    In this format: xxxx-xx-xx = 10 characters.

    $string = substr( $string, 11);

    So:
    $string = "2007-01-23 Filler Text";
    $string = substr( $string, 11);
    The Variable string would now be: " Filler Text".

    That is just one method. There are others such as picking up on formated wild cards, exploding/imploding the data array.

    -Jim
     
    Datawalke, Jun 26, 2007 IP
  3. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #3
    This method will work where ever the date is:

    
    $regex = "/[0-9]{4}-[0-9]{2}-[0-9]{2}/";
    $string = "A date 1975-05-14 is in here somewhere...";
    $new_string = "";
    	
    $new_string = preg_replace( $regex, '', $string );
    	
    echo $string . "<br /><br />";
    echo $new_string;
    PHP:
    Brew
     
    Brewster, Jun 26, 2007 IP