應該是這樣,簡單的格式問題盡量不用regular expression做
function changePhoneFormat($phoneNumber){
$check_number = substr($phoneNumber, 0, 2);
return $check_number == '09' ? '+886'.substr($phoneNumber, 1, strlen($phoneNumber)) : $phoneNumber;
}
$phoneNumber = '0928222444';
echo changePhoneFormat($phoneNumber);
+886928222444