SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little regex help needed.

    I need to seperate a title and a date from the same line.

    example:

    This would be a typical title followed by the date 2003.12.9.19:58.23

    Sometimes the title will have a number which is beyond my current regex knowledge to deal with without removing the date. And when I try and remove the date I get "Title ...:." which won't work. I need to return both the title and the date but seperate. Any help would be much appreciated.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Palo Alto
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you give a complete example string instead of just the date portion?
    I think there is a world market for maybe five computers.
    - Thomas Watson, chairman of IBM, 1943.

  3. #3
    ko pročita magarac :) boccio's Avatar
    Join Date
    Oct 2003
    Location
    belgrade
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what does "...title will have a number which is beyond my current regex knowledge ..." exactly mean? can u post such an example?

    the example u posted could be broken down like
    preg_match('~(\d+)\.(\d+)\.(\d+)\.(\d+)\:(\d+)\.(\d+)~iUs', $input_string, $time_date);

    so,
    $year = $time_date[0];
    $month= $time_date[1];
    ...
    $seconds = $time_date[5];

    didn't test this, but I think it should work...
    Vivvo CMS - Web publishing at your fingertips
    Mile voli disko, a ja belo kolumbijsko

  4. #4
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by boccio
    what does "...title will have a number which is beyond my current regex knowledge ..." exactly mean? can u post such an example?

    the example u posted could be broken down like
    preg_match('~(\d+)\.(\d+)\.(\d+)\.(\d+)\\d+)\.(\d+)~iUs', $input_string, $time_date);

    so,
    $year = $time_date[0];
    $month= $time_date[1];
    ...
    $seconds = $time_date[5];

    didn't test this, but I think it should work...
    An example would be.

    "1 thing happened today 2003.12.9.19:58.23"

    Then there is a number in the title portion as well as the date.

    $time_date[0] returned the whole date. thanks. I just onder what a number in the title portion would to to mess that up. Won't be able to test it till tonight.
    Thanks a bunch.

    Now how would I also grab the title and remove the date? Mybe just a pre_replace.

  5. #5
    ko pročita magarac :) boccio's Avatar
    Join Date
    Oct 2003
    Location
    belgrade
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, typo...disregard $time_date[0]

    $year = $time_date[1];
    $month= $time_date[2];
    ...
    $seconds = $time_date[6];

    this is how it goes...sorry for mistake
    I doesn't matter what text goes prior to year... it shall be disregarded (unless a number!) In that case regex needs modification...

    stay good
    Vivvo CMS - Web publishing at your fingertips
    Mile voli disko, a ja belo kolumbijsko

  6. #6
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works fine. even if there is a number in the text part of the title. Thanks. To get the text without the date I just did this.
    PHP Code:
    $title preg_replace('~(\d+)\.(\d+)\.(\d+)\.(\d+)\:(\d+)\.(\d+)~'''$target[$i]); 
    Seems to work fine.


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
  •