etiennetremel / PHP-Find-Date-in-String

Function to find a date in a string using Regular Expression
45 stars 14 forks source link

Small Error #6

Open hirbod opened 7 years ago

hirbod commented 7 years ago

This lib worked pretty good for me so far, but now I've found an error.

This is the text: Date 2017-01-01 Number 201701-19058-290719 mite. One activated user. Dec 01 Dec 31, 2016 4.20 Euro Net 4.20 Euro

(
    [year] => 2001
    [month] => 01
    [day] => 17
)

It should get the first line, 2017-01-01, instead it gets the invoice number, 201701-19058-290719, which your script tries to convert into a date.

Could you improve your reg-ex? Or at least return "all dates" inside the array? So I could iterate trough the array and make a DateTime isValid() check until I find the right date?

etiennetremel commented 6 years ago

Cool! @Vtvcode could you issue a PR with your fix?