- explode: documentation ( source)
- trim: documentation ( source)
- join: documentation ( source)
<?php
$oldtime = "20:30pm - 23:30pm";
$newtime = explode("-", $oldtime );
$arrStr = [];
$arrObj = [];
foreach($newtime as $elem) {
$o = DateTime::CreateFromformat( 'H:i+',trim($elem) );
$arrObj[] = $o;
$arrStr[] = $o->format('g:iA');
}
echo join(" - ",$arrStr);