homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

need regular expression(find date and numbers)

Msg#: 4482012 posted 5:30 pm on Aug 5, 2012 (gmt 0)

i have a string with this type content:
" 2012-02-12 my name is Smith . 2020-11-05 hello world 1234678... "
i want to get all dates and replace thats with other string.
i need regular expression for fetch dates.
please help me




WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4482012 posted 5:31 pm on Aug 5, 2012 (gmt 0)

Let's see your example code...


Msg#: 4482012 posted 6:07 pm on Aug 5, 2012 (gmt 0)

$string = '
John Smith birth date : 1989-02-11
Joe Smith birth date : 1991-09-10
Kitty Smith birth date : 1977-12-01
Lora Smith birth date : 1984-05-25
Josef Smith birth date : 1995-02-14
////Simulated Codes
in string foreach $birthdate as $date
$unixtime = strtotime(date);
replcae(date ,$unixtime )


WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4482012 posted 10:07 pm on Aug 5, 2012 (gmt 0)

Seems like overkill. Do you have code at an earlier stage that forces dates into the form you've shown, yyyy-mm-dd ? If so you should be able to just tweak that code and work backward.

Picking up the yyyy-mm-dd piece as a raw Regular Expression, independent of content,* is so trivial that I'm not going to insult your intelligence by writing it out.So I assume you're really asking something a little more complicated ;)

* That is, if you don't care whether the person claims to have been born on 2012-08-05 or 1776-02-31 or even 2555-55-55. If the first-round code was careful, the third form will definitely never occur, probably not the second and maybe not the first.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved