Do you need to check for empty on $matches[1] and $matches[2]?  If they are empty, it means the preg_match failed and code execution wouldn't get here.