python72 Posted December 2, 2010 Share Posted December 2, 2010 I have another question related to string searches. What I have is a string of couple thousand characters of all types but the date format is allways the same: dd-mth-year (two digits for day-three letters for month-four digits for year). Can I use the format alone to determine where the date is located which in turn would make it very easy to store that date into variables for inserting into database, etc. Is there anyway to tell php the format to look for or do I have to have actual numbers/letters to perform the search? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 2, 2010 Share Posted December 2, 2010 You can use regular expressions. Just keep in mind that what you get out won't be any better than what you put in. var_dump(preg_match_all('/\d\d-[a-z][a-z][a-z]-\d\d\d\d/i', $text)); What I mean by that is that it would be a Good Idea to be more specific than "three letters" for the month. List the possibilities out. (jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) Quote Link to comment Share on other sites More sharing options...
python72 Posted December 3, 2010 Author Share Posted December 3, 2010 It works, thanks. I just would like to know what is the i for at the end of pattern string? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 3, 2010 Share Posted December 3, 2010 http://php.net/reference.pcre.pattern.modifiers It means any letters in the expression are case-insensitive. Quote Link to comment Share on other sites More sharing options...
python72 Posted December 7, 2010 Author Share Posted December 7, 2010 One more pattern question which just came up and the way I am trying to do it is not working. If the date is in the following format: December 04, 2010 I have to came up with different pattern, I thought that the following pattern would work: $Pattern='/(January|February|March|April|May|June|July|August|September|October|November|December) \d\d, \d\d\d\d/i'; but it does not work, not sure how to fix it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.