SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex date search

    hi - i'm having trouble with a little function here. in the larger context of its use, what i'd like it to do is strip the date and time information from the footer of an xml feed. the footers look like the string being sent to the findcost function below. I thought i'd use some pretty basic regex to find the date portion. I just want to cut off everything after the three letter date. for some reason when i print $found it returns blank. I just want to look for a string which contains any of the three latter dates. anyone know what's going on here?

    separately but maybe somewhat relatedly, if i just put "Mar" as the value of $dates, it still doesn't work - whereas if i put "Mar" right into the strstr it works fine. hmm.

    Code:
    <?php
    $dates = "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec";
    function findcost($val){
    $found = strstr($val, $dates);
    print $found; 
    $chardelete = str_replace($found,"",$found);
    return $chardelete;
    }
    
    ?>

    ian
    signature

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first, that's not a regular expression.

    second, $dates isn't defined in the function, which is why it's not working there. so you'll need to move the $dates declaration into the function or something.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks - silly of me there. I've never used regular expressions - i was going by this tutorial http://www.phpbuilder.com/columns/dario19990616.php3 - specifically the line:

    "hi|hello": matches a string that has either "hi" or "hello" in it;

    and yet this doesn't work in mine - not sure what i'm doing wrong.
    signature


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
  •