Tuesday 15 September 2015

php - Find unknown formatted date in string -


I am currently struggling with a problem: I am trying to find an (unknown formatted) date inside a given string. I've applied a solution for the German dates ( dd.mm.yyyy ):
  if (preg_match ('/ \ d {2}.' \ '{2}. \ D {4} /', $ stringWithDate from anywhere, $ date) {$ results ['date'] = date ('ym-d', stratomet ($ date [0])); }   

I can continue to add many regg expressions to match the most common. The problem is that there are so many possible formats to check because German dates are not checked for this.

Is there a PHP class or function to find the date inside the string such as iPhone with e-mails and websites?

$ stringWithDate from anywhere :

  An example  
 . I know that, just for a friend, I want to ask for my friend. For the current time * 19.13.2013 * In this situation, it is estimated that Curabitur * 2 February 2011 * Vitae pellentesque dui, mi     

description

This expression will capture you in two formats Your sample text is a string of steps to ensure it's a valid date Does not check.

  • Match the format of 31.43.2013 where two delimiters are not letters or numbers and are identical
  • 2 February 2011 < / Code> is a format where there is a digit, one month and a 4 digit string

    \ d {1,4} ([^ A- Z0-9 ]) \ D {1,4} \ 1 \ d {1,4} | \ D (ct | nd | th | th) \ s (Jan | Feb | Mar | Apr | May | Jun | July | Aug | Sep | Oct | Dec | Dec] [az] * \ b \ s? \ D {4}

    Enter image details here

    PHP code example:

    Input Text A website is ready for the website, I know that, I just got a For a friend, I want to ask for my friend. For the current time * 19.13.2013 * In this situation, it is estimated that Curabitur * 2 February 2011 * Vitae pellentesque dui, mi

    Code

      & lt ;? Php $ sourcestring = "your source string"; Preg_match_all ('/ \ d {1,4} ([^ a-z0-9]) \ d {1,4} \ 1 \ d {1,4} | \ d (: cents | th | th | th? ) \ S (?: January | Feb | Mar | Apr | May | Jun | July | Aug | Sep | Oct | Nov | Dec | Dec] [az] * \ b \ s \ d {4} / im ', $ Sourcestring matches $$); Echo "& lt; east & gt;" Print_r ($ match, true); ? & Gt;   

    Matches

      $ matches Array: ([0] = & gt; Array ([0] = & gt; ; 19.10 2013 [1] = & gt; 2 February 2011) [1] => Array ([0] => [1] = & gt;))   

    Disclaimer

    There are many corner issues that this expression is not available.

    Expression can also catch things that are not really, it is normal.

No comments:

Post a Comment