本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::formatByPattern方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::formatByPattern方法的具體用法?PHP PhoneNumberUtil::formatByPattern怎麽用?PHP PhoneNumberUtil::formatByPattern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::formatByPattern方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testFormatByPattern
public function testFormatByPattern()
{
$newNumFormat = new NumberFormat();
$newNumFormat->setPattern("(\\d{3})(\\d{3})(\\d{4})");
$newNumFormat->setFormat("(\$1) \$2-\$3");
$newNumberFormats = array();
$newNumberFormats[] = $newNumFormat;
$this->assertEquals("(650) 253-0000", $this->phoneUtil->formatByPattern(self::$usNumber, PhoneNumberFormat::NATIONAL, $newNumberFormats));
$this->assertEquals("+1 (650) 253-0000", $this->phoneUtil->formatByPattern(self::$usNumber, PhoneNumberFormat::INTERNATIONAL, $newNumberFormats));
$this->assertEquals("tel:+1-650-253-0000", $this->phoneUtil->formatByPattern(self::$usNumber, PhoneNumberFormat::RFC3966, $newNumberFormats));
// $NP is set to '1' for the US. Here we check that for other NANPA countries the US rules are
// followed.
$newNumFormat->setNationalPrefixFormattingRule('$NP ($FG)');
$newNumFormat->setFormat("\$1 \$2-\$3");
$this->assertEquals("1 (242) 365-1234", $this->phoneUtil->formatByPattern(self::$bsNumber, PhoneNumberFormat::NATIONAL, $newNumberFormats));
$this->assertEquals("+1 242 365-1234", $this->phoneUtil->formatByPattern(self::$bsNumber, PhoneNumberFormat::INTERNATIONAL, $newNumberFormats));
$newNumFormat->setPattern("(\\d{2})(\\d{5})(\\d{3})");
$newNumFormat->setFormat("\$1-\$2 \$3");
$newNumberFormats[0] = $newNumFormat;
$this->assertEquals("02-36618 300", $this->phoneUtil->formatByPattern(self::$itNumber, PhoneNumberFormat::NATIONAL, $newNumberFormats));
$this->assertEquals("+39 02-36618 300", $this->phoneUtil->formatByPattern(self::$itNumber, PhoneNumberFormat::INTERNATIONAL, $newNumberFormats));
$newNumFormat->setNationalPrefixFormattingRule('$NP$FG');
$newNumFormat->setPattern("(\\d{2})(\\d{4})(\\d{4})");
$newNumFormat->setFormat("\$1 \$2 \$3");
$newNumberFormats[0] = $newNumFormat;
$this->assertEquals("020 7031 3000", $this->phoneUtil->formatByPattern(self::$gbNumber, PhoneNumberFormat::NATIONAL, $newNumberFormats));
$newNumFormat->setNationalPrefixFormattingRule('($NP$FG)');
$this->assertEquals("(020) 7031 3000", $this->phoneUtil->formatByPattern(self::$gbNumber, PhoneNumberFormat::NATIONAL, $newNumberFormats));
$newNumFormat->setNationalPrefixFormattingRule("");
$this->assertEquals("20 7031 3000", $this->phoneUtil->formatByPattern(self::$gbNumber, PhoneNumberFormat::NATIONAL, $newNumberFormats));
$this->assertEquals("+44 20 7031 3000", $this->phoneUtil->formatByPattern(self::$gbNumber, PhoneNumberFormat::INTERNATIONAL, $newNumberFormats));
}