Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my improved version and I think complete. Only errors and warnings are not taken into account.</p> <pre><code>if( !function_exists('date_parse_from_format') ){ function date_parse_from_format($format, $date) { // reverse engineer date formats $keys = array( 'Y' =&gt; array('year', '\d{4}'), //Année sur 4 chiffres 'y' =&gt; array('year', '\d{2}'), //Année sur 2 chiffres 'm' =&gt; array('month', '\d{2}'), //Mois au format numérique, avec zéros initiaux 'n' =&gt; array('month', '\d{1,2}'), //Mois sans les zéros initiaux 'M' =&gt; array('month', '[A-Z][a-z]{3}'), //Mois, en trois lettres, en anglais 'F' =&gt; array('month', '[A-Z][a-z]{2,8}'), //Mois, textuel, version longue; en anglais, comme January ou December 'd' =&gt; array('day', '\d{2}'), //Jour du mois, sur deux chiffres (avec un zéro initial) 'j' =&gt; array('day', '\d{1,2}'), //Jour du mois sans les zéros initiaux 'D' =&gt; array('day', '[A-Z][a-z]{2}'), //Jour de la semaine, en trois lettres (et en anglais) 'l' =&gt; array('day', '[A-Z][a-z]{6,9}'), //Jour de la semaine, textuel, version longue, en anglais 'u' =&gt; array('hour', '\d{1,6}'), //Microsecondes 'h' =&gt; array('hour', '\d{2}'), //Heure, au format 12h, avec les zéros initiaux 'H' =&gt; array('hour', '\d{2}'), //Heure, au format 24h, avec les zéros initiaux 'g' =&gt; array('hour', '\d{1,2}'), //Heure, au format 12h, sans les zéros initiaux 'G' =&gt; array('hour', '\d{1,2}'), //Heure, au format 24h, sans les zéros initiaux 'i' =&gt; array('minute', '\d{2}'), //Minutes avec les zéros initiaux 's' =&gt; array('second', '\d{2}') //Secondes, avec zéros initiaux ); // convert format string to regex $regex = ''; $chars = str_split($format); foreach ( $chars AS $n =&gt; $char ) { $lastChar = isset($chars[$n-1]) ? $chars[$n-1] : ''; $skipCurrent = '\\' == $lastChar; if ( !$skipCurrent &amp;&amp; isset($keys[$char]) ) { $regex .= '(?P&lt;'.$keys[$char][0].'&gt;'.$keys[$char][1].')'; } else if ( '\\' == $char ) { $regex .= $char; } else { $regex .= preg_quote($char); } } $dt = array(); // now try to match it if( preg_match('#^'.$regex.'$#', $date, $dt) ){ foreach ( $dt AS $k =&gt; $v ){ if ( is_int($k) ){ unset($dt[$k]); } } if( !checkdate($dt['month'], $dt['day'], $dt['year']) ){ $dt['error_count'] = 1; } else { $dt['error_count'] = 0; } } else { $dt['error_count'] = 1; } $dt['errors'] = array(); $dt['fraction'] = ''; $dt['warning_count'] = 0; $dt['warnings'] = array(); $dt['is_localtime'] = 0; $dt['zone_type'] = 0; $dt['zone'] = 0; $dt['is_dst'] = ''; return $dt; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload