This isn't really an elegant solution but it works, if the inspection date never truly deviates from how it is displayed.
$str = "<inspection>21-Oct-2018 10:30AM to 10:50AM</inspection>";
preg_match('/(\d+\-[A-Za-z]+\-\d{4})\s(.+\s.+\M)/',$str,$temp);
echo $temp[1]."\n";
echo $temp[2]."\n";
Outputs
21-Oct-2018
10:30AM to 10:50AM
Use https://regex101.com/ for explanation of Regular Expression as I could not do it justice with my explanation.
Hope this helps.
as function:
function sep_times($str){
preg_match('/(\d+\-[A-Za-z]+\-\d{4})\s(.+\s.+\M)/',$str,$temp);
return $temp;
}
Use:
$variable = sep_times($your_xml_string); //"<inspection>21-Oct-2018 10:30AM to 10:50AM</inspection>"
echo $variable[0]; //outputs 21-Oct-2018 10:30AM to 10:50AM
echo $variable[1]; //outputs 21-Oct-2018
echo $variable[2]; //outputs 10:30AM to 10:50AM