Skip to content

Instantly share code, notes, and snippets.

@inuvalogic
Last active June 23, 2023 10:27
Show Gist options
  • Save inuvalogic/5a915955a7614c2ee2f6debcce2035e5 to your computer and use it in GitHub Desktop.
Save inuvalogic/5a915955a7614c2ee2f6debcce2035e5 to your computer and use it in GitHub Desktop.
replace 0 to 62 or other country code for whatsapp link wa.me
<?php
// replace 081234567890 or 6281234567890 or +6281234567890 or 62 812 34 567 890
// to 6281234567890 for whatsapp link http://wa.me/62xxxxx
function phoneFormat($number, $country_code = '62')
{
$number = str_replace('+', '', $number);
$number = str_replace(' ', '', $number);
$number = preg_replace('/^0/', $country_code, $number);
return $number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment