Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlifArnado/3893d5d77da35fc99e18f339aec55391 to your computer and use it in GitHub Desktop.
Save AlifArnado/3893d5d77da35fc99e18f339aec55391 to your computer and use it in GitHub Desktop.
fungsi untuk mengubah nomor telepon yang di depan ada terjadi inputan +62 dan 62 untuk di ubah menjadi 08 atau menghapus angka +62 atau 62 kode area indonesia menjadi 08 normal nomor telepon
function regex_no_hp_62_0($nohp) {
$no = "";
if (preg_match('/^(?:\+62)/',trim($nohp))) {
// echo "ada tanda +62 <br>";
$no = substr_replace($nohp,'0',0,3);
} else if (preg_match('/^(?:62)/',trim($nohp))) {
// echo "ada tanda 62 <br>";
$no = substr_replace($nohp,'0',0,2);
} else {
// echo "number yg di cari 08 <br>";
$no = $nohp;
}
return $no;
}
$nohp = "+628562121141";
print_r(regex_no_hp_62_0($nohp));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment