1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php regex on whois

Discussion in 'PHP' started by thesurface, Nov 8, 2015.

  1. #1
    Domain Expiration Date: Mon May 23 23:59:59 GMT 2016

    how can i get 23 May 2016 via regex? is that possible as i will use it in my script for other domains formatted whois like that
     
    Solved! View solution.
    thesurface, Nov 8, 2015 IP
  2. #2
    If that's always formatted that way, you don't need regex.
    You could just do a simple explode (or, rather, two explodes) and then pull the info from the array returned
     
    PoPSiCLe, Nov 8, 2015 IP
  3. thesurface

    thesurface Active Member

    Messages:
    260
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Yeah exploding it would be the best thx!!!
     
    thesurface, Nov 8, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    You may be better off with that explode only splitting by the first colon...

    list($title, $date) = explode(':', $line, 2);

    Then you could use dateTime::createFromFormat to turn it into a proper dateTime object so you could do whatever you wanted with it, in your case:

    Mon May 23 23:59:59 GMT 2016
    $date = DateTime::createFromFormat('D M d H:I:S e Y');

    The M and d above may be L and j respectively, hard to tell from that particular date if it's three letter or full month name, or leading zero on days or not... but createFromFormat is usually pretty forgiving on that.

    http://php.net/manual/en/datetime.createfromformat.php

    PHP... yeah, there's a function or object method for that...
     
    deathshadow, Nov 8, 2015 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Fancy - haven't really encountered createFromFormat before. Seems to be a better solution, depending on what is needed.
     
    PoPSiCLe, Nov 8, 2015 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Did we mention I read two pages of PHP.net a night before bed?

    There's a LOT of stuff I see people "brute force" that I go "wait, doesn't PHP already have a function for that?". Using the native functions which are most always compiled code is most always going to be faster than hard-coding data processing; it's one of PHP's biggest strengths...

    But it's also a weakness as the function and object libraries are so huge, nobody can remember all of it at once. It's why I try to just remember "there is a function for that" and then pull it up on php.net when I need to use it. I remembered that object method existed, but I forgot the exact syntax or even it's full and proper name -- so I had to look it up while posting.

    Part of why despite all my complaints about PHP it's still my first choice for web programming -- the robust function library and brilliant documentation that leaves every other blasted language in the dust on both counts.

    Again though, I was spoiled by the really good Borland print manuals in the late '80's and early '90's, so I come at what I expect for documentation with far higher expectations than everyone else.
     
    deathshadow, Nov 8, 2015 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    What I wish for is a better search-function on php.net. More like Googles "guesswork" - "did you mean to search for this" and so forth. That would help, especially when you can't remember the exact name of the function, and have to go on "tags", not to mention the absolutely horrendous mix-matching of function names in PHP. Some are with camel-case, some with underscore, some without anything at all. Sometimes, it's very annoying.
     
    PoPSiCLe, Nov 9, 2015 IP