/    Sign up×
Community /Pin to ProfileBookmark

strpos (date)

I’m looking to pull out any dates from my story. I assume I’ll do strpos to see if there’s any dates but given there’s so many variations around format. How could I design a needle or a few common needles?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@kiwisauthorDec 29.2021 — One common format seems to be day of week, day of month followed by month.

Friday 13 May

Friday 13th May

I could do pre_match any work ending day, followed by 1 or 2 digits followed by a work between 3 and 6 letters May & September. A second pattern could include st, th, rd

I'm not good at these

<i>
</i>$pattern = "/w+daysd{1,2}(st|th|rd)sw+/";
$pattern2 = "/w+daysd{1,2}/";


Another option is looking for reference to a day, say Tuesday, but I'd need to see reference to ''kickoff' a few works either side. The I could strtotime('this tuesday'). But I'm not sure how to check works either side.
Copy linkTweet thisAlerts:
@NogDogDec 29.2021 — You'd want to use preg_match_all() for that, most likely. But if you have no control over what formats are used in the text, you're going to have to come up with a lot of patterns, plus figure out how to tell if 10/11/2012 is October 11 or November 10 (if it matters?). Just the various number-only formats are numerous, without even delving into dealing with month names and abbreviations.
Copy linkTweet thisAlerts:
@kiwisauthorDec 29.2021 — That's what I'm thinking, I'll need to do several patterns.
Copy linkTweet thisAlerts:
@NogDogDec 29.2021 — @kiwis80#1640973 "several" may be conservative. ;)
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...