$time = preg_replace('/(\d+):(\d+):\d+/e', '($1<12)?"$1:$2 AM":$1-12 . ":$2 PM"', $time);
Here, first I have taken the hour and minute portion from the time using regular expression. It will be at $1 and $2 variables. Then inside the replacement section, I have checked whether the hour is less than 12 or not ($1<12), using this I have placed the AM or PM after the hh:mm, and also I have deducted 12 from hour section if it is more than 12.
This regular expression may comes hard to understand, but this is only for REGEX lovers who wants to convert the 24 hours time format into 12 hrs AM-PM time format. Cheers!!!