zipavlin/phony

A helper class for parsing, normalizing and displaying Slovene phone numbers

Installs: 489

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:laravel-package

1.2.0 2022-09-15 03:38 UTC

This package is auto-updated.

Last update: 2024-12-15 08:35:59 UTC


README

A phone number parser tailored for Slovene number format.

Install

$ composer require zipavlin/phony

Quick start

use Zipavlin\Phony;
$phony = new Phony()

echo $phony->from('041 123-456')->toDisplay(); // +386 (0)41 123 456
echo $phony->from('041 123 456')->toFormat('00386 0{area}/{number:2}-{number:2}-{number}'); // 00386 041/12-34-56
echo $phony->from('01 1234-567')->toDisplay(); // +386 (0)1 12 34 567

Methods

Format string

$format attribute can be either string or array [string, string], where first format string is used for mobile numbers and second one is used for stationary phone numbers.

Format tokens

  • {area} - area code without leading zero
  • {number} - rest of phone number

Both tokens have an optional characters-count parameter: {area:2} and {number:3} respectively.

Format example

Working with phone number 041 123456 {area}/{number:5}-{number} would return 41/12345-6
{area:1}-{area:1} {number} would return 4-1 123456
0{area}/{number:3} {number:6} would return 041/123 456