@ 2015-07-01T06:34:07Z <?php
function find_date( $string ) {
//Define month name:
$month_names = array(
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december"
);
$month_number=$month=$matches_year=$year=$matches_month_number=$matches_month_word=$matches_day_number="";
//Match dates: 01/01/2012 or 30-12-11 or 1 2 1985
preg_match( '/([0-9]?[0-9])[\.\-\/ ]?([0-1]?[0-9])[\.\-\/ ]?([0-9]{2,4})/', $string, $matches );
if ( $matches ) {
if ( $matches[1] )
$day = $matches[1];
if ( $matches[2] )
$month = $matches[2];
if ( $matches[3] )
$year = $matches[3];
}
//Match month name:
preg_match( '/(' . implode( '|', $month_names ) . ')/i', $string, $matches_month_word );
echo $matches_month_word;exit;
if ( $matches_month_word ) {
if ( $matches_month_word[1] )
$month = array_search( strtolower( $matches_month_word[1] ), $month_names ) + 1;
}
//Match 5th 1st day:
preg_match( '/([0-9]?[0-9])(st|nd|th)/', $string, $matches_day );
if ( $matches_day ) {
if ( $matches_day[1] )
$day = $matches_day[1];
}
//Match Year if not already setted:
if ( empty( $year ) ) {
preg_match( '/[0-9]{2}/', $string, $matches_year );
if ( $matches_year[0] )
$year = $matches_year[0];
}
if ( ! empty ( $day ) && ! empty ( $month ) && empty( $year ) ) {
preg_match( '/[0-9]{2}/', $string, $matches_year );
if ( $matches_year[0] )
$year = $matches_year[0];
}
$day = '01';
//Leading 0
if ( 1 == strlen( $day ) )
$day = '0' . $day;
//Leading 0
if ( 1 == strlen( $month ) )
$month = '0' . $month;
//Check year:
if ( 2 == strlen( $year ) && $year > 20 )
$year = '19' . $year;
else if ( 2 == strlen( $year ) && $year < 20 )
$year = '20' . $year;
$date = array(
'year' => $year,
'month' => $month,
'day' => $day
);
//Return false if nothing found:
if ( empty( $year ) && empty( $month ) && empty( $day ) )
return false;
else
return date('Y-m-d',strtotime($date['year'].'-'.$date['month'].'-01'));
}
echo find_date('Fund Factsheet Syariah - Jan 1914');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 Warning: Array to string conversion in /in/A4XIG on line 33
Array Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Warning: Array to string conversion in /in/A4XIG on line 33
Array Output for 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 Notice: Array to string conversion in /in/A4XIG on line 33
Array Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 7.3.32 - 7.3.33 Array preferences:dark mode live preview
311.57 ms | 402 KiB | 356 Q