Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added demo file

  • Loading branch information...
commit b9dd751402266910c1a553883787c6f230dbb02f 1 parent d3882b5
Davide Mendolia authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 demo.php
11 demo.php
View
@@ -1,13 +1,14 @@
<?php
use com\google\i18n\phonenumbers\PhoneNumberUtil;
-use com\google\i18n\phonenumbers\PhoneNumber;
+use com\google\i18n\phonenumbers\PhoneNumberFormat;
+use com\google\i18n\phonenumbers\NumberParseException;
require_once 'PhoneNumberUtil.php';
$swissNumberStr = "044 668 18 00";
$phoneUtil = PhoneNumberUtil::getInstance();
try {
- $swissNumberProto = $phoneUtil->parse($swissNumberStr, "CH");
+ $swissNumberProto = $phoneUtil->parseAndKeepRawInput($swissNumberStr, "CH");
var_dump($swissNumberProto);
} catch (NumberParseException $e) {
echo $e;
@@ -15,4 +16,8 @@
$isValid = $phoneUtil->isValidNumber($swissNumberProto);//return true
var_dump($isValid);
// Produces "+41446681800"
-echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::E164) . PHP_EOL;
+echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::INTERNATIONAL) . PHP_EOL;
+echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::NATIONAL) . PHP_EOL;
+echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::E164) . PHP_EOL;
+
+echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "US") . PHP_EOL;
Please sign in to comment.
Something went wrong with that request. Please try again.