Nothing found

Phone number

The BulkGate\Sms\Message\PhoneNumber class represents the phone number object.

use BulkGate\Sms\Message\PhoneNumber;

The constructor accepts the required parameter phone number and optional country ISO code.

$phone_number = new PhoneNumber( "420777777777", BulkGate\Sms\Country::UNITED_KINGDOM );

The second parameter is required if you enter a number in the national format. If you enter a phone number in the national format and don't enter the ISO 3166-1 alpha-2 code, BulkGate will fill the international prefix according to the country listed in your user account.

You can also change the phone number after creating an instance.

/** @var BulkGate\Sms\Message\PhoneNumber $phone_number */ $phone_number->phoneNumber('447971700001');

You can also set the ISO code.

/** @var BulkGate\Sms\Message\PhoneNumber $phone_number */ $phone_number->iso(BulkGate\Sms\Country::UNITED_KINGDOM); // nebo $phone_number->iso('gb');

In case of invalid ISO code, an exception BulkGate\Sms\Message\InvalidPhoneNumberException is called

Convert to JSON

/** @var BulkGate\Sms\Message\PhoneNumber $phone_number */ echo json_encode($phone_number);

The output is:

{ "number": "447971700001", "iso": null }

Other

Obtain a formatted phone number in a string

/** @var BulkGate\Sms\Message\PhoneNumber $phone_number */ $phone_number->getPhoneNumber(); $number = (string) $phone_number; echo $phone_number;

Obtaining an ISO code

/** @var BulkGate\Sms\Message\PhoneNumber $phone_number */ $phone_number->getIso(); // returns a string or null

It also supports fluent interface

/** @var BulkGate\Sms\Message\PhoneNumber $phone_number */ $phone_number ->phoneNumber('7971700001') ->iso(BulkGate\Sms\Country::UNITED_KINGDOM);
Was this page helpful?