Regex PHP find 2 words same position -
i want apply regex find english month when search month string in spanish or other idiom. have array of possible matches:
$monthsidioms = array( 'en' => array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'), 'es' => array( '/ene/', '/feb/', '/mar/', '/abr/', '/may/', '/jun/', '/jul/', '/ago/', '/sep/', '/oct/', '/nov/', '/dic/' ));
but date variable can have format:
$date = "24 ene 15:45";
or one:
$date = "24 enero 15:45";
so need regex find ene or enero in date , other months:
'es' => array( '/ene|enero/', '/feb|febrero/', '/mar|marzo/', '/abr|abril/', '/may|mayo/', '/jun|junio/', '/jul|julio/', '/ago|agosto/', '/set|septiembre/', '/oct|octubre/', '/nov|noviembre/', '/dic|diciembre/' )
and call with:
preg_replace($monthsidioms['es'], $monthsidioms['en'], $date);
but regex | not working. dong wrong?
note 'es' array regex strings.
so clarify this, want if have date: "24 ene 15:45" or this: "24 enero 15:45" converted to: "24 jan 15:45" same with other month of year: "24 ago 15:45" or "24 agosto 15:45" "24 aug 15:45".
well since short names of month inside actual name of month add space:
'en' => array('jan ', 'feb ', 'mar ', 'etc'), 'es' => array('/ene |enero /','/feb |febrero /','/mar |marzo / ','etc')
Comments
Post a Comment