- var_dump: documentation ( source)
- preg_match: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
<?php
$data = [
[
'blah' => 'reference',
],
[
'A' => 'SMI13',
'B' => '03/12/1940',
'C' => '',
]
];
foreach($data as &$record){
foreach($record as $key => $val){
//you might want to consider using preg_replace_callback instead:
if(preg_match("/^(((0[13578]|1[02])\/(0[1-9]|[12]\d|3[01])\/((19|[2-9]\d)\d{2}))|((0[13456789]|1[012])\/(0[1-9]|[12]\d|30)\/((19|[2-9]\d)\d{2}))|(02\/(0[1-9]|1\d|2[0-8])\/((19|[2-9]\d)\d{2}))|(02\/29\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/",$val)) {
echo "match! $val \n";
$record [$key] = date("Y-m-d", strtotime($val));
}
}
}
unset($record);
var_dump($data);