[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/HTML/Helpers/ -> Telephone.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\HTML\Helpers;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * HTML helper class for rendering telephone numbers.
  18   *
  19   * @since  1.6
  20   */
  21  abstract class Telephone
  22  {
  23      /**
  24       * Converts strings of integers into more readable telephone format
  25       *
  26       * By default, the ITU-T format will automatically be used.
  27       * However, one of the allowed unit types may also be used instead.
  28       *
  29       * @param   integer  $number       The integers in a phone number with dot separated country code
  30       *                                 ccc.nnnnnnn where ccc represents country code and nnn represents the local number.
  31       * @param   string   $displayplan  The numbering plan used to display the numbers.
  32       *
  33       * @return  string  The formatted telephone number.
  34       *
  35       * @see     \Joomla\CMS\Form\Rule\TelRule
  36       * @since   1.6
  37       */
  38      public static function tel($number, $displayplan)
  39      {
  40          $number = explode('.', $number);
  41          $countrycode = $number[0];
  42          $number = $number[1];
  43  
  44          if ($displayplan === 'ITU-T' || $displayplan === 'International' || $displayplan === 'int' || $displayplan === 'missdn' || $displayplan == null) {
  45              $display[0] = '+';
  46              $display[1] = $countrycode;
  47              $display[2] = ' ';
  48              $display[3] = implode(' ', str_split($number, 2));
  49          } elseif ($displayplan === 'NANP' || $displayplan === 'northamerica' || $displayplan === 'US') {
  50              $display[0] = '(';
  51              $display[1] = substr($number, 0, 3);
  52              $display[2] = ') ';
  53              $display[3] = substr($number, 3, 3);
  54              $display[4] = '-';
  55              $display[5] = substr($number, 6, 4);
  56          } elseif ($displayplan === 'EPP' || $displayplan === 'IETF') {
  57              $display[0] = '+';
  58              $display[1] = $countrycode;
  59              $display[2] = '.';
  60              $display[3] = $number;
  61          } elseif ($displayplan === 'ARPA' || $displayplan === 'ENUM') {
  62              $number = implode('.', str_split(strrev($number), 1));
  63              $display[0] = '+';
  64              $display[1] = $number;
  65              $display[2] = '.';
  66              $display[3] = $countrycode;
  67              $display[4] = '.e164.arpa';
  68          }
  69  
  70          return implode('', $display);
  71      }
  72  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer